Maven命令列出生命周期阶段以及绑定目标?

Upg*_*ave 93 maven-2 maven-3

我只是在学习Maven,所以这可能很明显,但我找不到一个简单的方法来列出给定项目的每个maven生命周期阶段的相关目标.

我看到Maven默认生命周期阶段和相应的默认目标都记录在这里.到目前为止,我的理解是每个pom.xml都可以为每个生命周期阶段绑定其他目标.

那么,是否有一个mvn命令来确定将为给定项目的每个生命周期阶段运行的目标?如果没有,我想我只需要查看每个新maven项目的pom.xml来解决这个问题?

小智 122

mvn help:describe -Dcmd=compile (或任何其他有效阶段)

  • 在此命令的输出中没有看到与阶段有关的目标。相反,我看到的是插件/阶段。 (2认同)

Cha*_*uis 112

buildplan-maven-plugin是展示目标如何与阶段相结合的绝佳工具.

以下是您可以运行的命令示例.如果尚未安装插件,命令将自动下载并安装插件.

按照他们将执行的顺序列出目标

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list

PLUGIN                  | PHASE                  | ID                    | GOAL
--------------------------------------------------------------------------------------------
maven-enforcer-plugin   | validate               | default               | enforce
maven-dependency-plugin | process-sources        | default               | copy-dependencies
maven-resources-plugin  | process-resources      | default-resources     | resources
maven-compiler-plugin   | compile                | default-compile       | compile
maven-resources-plugin  | process-test-resources | default-testResources | testResources
maven-compiler-plugin   | test-compile           | default-testCompile   | testCompile
maven-surefire-plugin   | test                   | default-test          | test
maven-jar-plugin        | package                | default-jar           | jar
maven-assembly-plugin   | package                | make-assembly         | single
maven-install-plugin    | install                | default-install       | install
maven-deploy-plugin     | deploy                 | default-deploy        | deploy
Run Code Online (Sandbox Code Playgroud)

按阶段分组目标

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-phase

validate -----------------------------------------------------------------
    + maven-enforcer-plugin   | default               | enforce
process-sources ----------------------------------------------------------
    + maven-dependency-plugin | default               | copy-dependencies
process-resources --------------------------------------------------------
    + maven-resources-plugin  | default-resources     | resources
compile ------------------------------------------------------------------
    + maven-compiler-plugin   | default-compile       | compile
process-test-resources ---------------------------------------------------
    + maven-resources-plugin  | default-testResources | testResources
test-compile -------------------------------------------------------------
    + maven-compiler-plugin   | default-testCompile   | testCompile
test ---------------------------------------------------------------------
    + maven-surefire-plugin   | default-test          | test
package ------------------------------------------------------------------
    + maven-jar-plugin        | default-jar           | jar
    + maven-assembly-plugin   | make-assembly         | single
install ------------------------------------------------------------------
    + maven-install-plugin    | default-install       | install
deploy -------------------------------------------------------------------
    + maven-deploy-plugin     | default-deploy        | deploy
Run Code Online (Sandbox Code Playgroud)

插件组目标

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list-plugin

maven-enforcer-plugin ---------------------------------------------------
    + validate               | default               | enforce
maven-dependency-plugin -------------------------------------------------
    + process-sources        | default               | copy-dependencies
maven-resources-plugin --------------------------------------------------
    + process-resources      | default-resources     | resources
    + process-test-resources | default-testResources | testResources
maven-compiler-plugin ---------------------------------------------------
    + compile                | default-compile       | compile
    + test-compile           | default-testCompile   | testCompile
maven-surefire-plugin ---------------------------------------------------
    + test                   | default-test          | test
maven-jar-plugin --------------------------------------------------------
    + package                | default-jar           | jar
maven-assembly-plugin ---------------------------------------------------
    + package                | make-assembly         | single
maven-install-plugin ----------------------------------------------------
    + install                | default-install       | install
maven-deploy-plugin -----------------------------------------------------
    + deploy                 | default-deploy        | deploy
Run Code Online (Sandbox Code Playgroud)

笔记

默认情况下,目标搜索在用户调用时将运行的任务mvn deploy.阶段如clean不包括在内.要在搜索中包含多个阶段,请使用以下buildplan.tasks属性:

> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks=clean,deploy
Run Code Online (Sandbox Code Playgroud)

  • 默认情况下,这应该真正内置到Maven中. (29认同)
  • 也可以在不调整pom的情况下工作:`mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks = clean,install,deploy` (3认同)

Aar*_*lla 15

一个有用的工具是mvn help:effective-pom它将打印包含所有变量的POM,并扩展所有父POM.这有助于理解Maven看到的内容.从那里,找到所有额外的目标(通常不是那么多)非常简单.

更大的问题是隐含目标(即当插件自动挂钩到生命周期的某些阶段时).没有实际运行Maven就没有简单的方法可以看到这些.这应该在Maven 3中变得更好.在那之前,运行Maven -X将打印大量的调试输出加上当前阶段以及执行​​哪些插件.

  • Jason告诉我,新的Maven 3将在实际启动之前构建整个构建的模型.这意味着您可以在不运行命令的情况下检查(并打印)挂钩. (2认同)