我只是在学习Maven,所以这可能很明显,但我找不到一个简单的方法来列出给定项目的每个maven生命周期阶段的相关目标。
我看到Maven默认生命周期阶段和相应的默认目标都记录在案here。到目前为止,我的理解是每个pom.xml都可以为每个生命周期阶段绑定其他目标。
那么,是否有一个mvn命令来确定为给定项目的每个生命周期阶段运行的目标?如果没有,我想我只需要查看每个新maven项目的pom.xml来解决这个问题吗?
答案 0 :(得分:117)
mvn help:describe -Dcmd=compile
(或任何其他有效阶段)
答案 1 :(得分:96)
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
> 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
> 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
默认情况下,目标搜索在用户调用mvn deploy
时将运行的任务。不包括clean
等阶段。要在搜索中包含多个阶段,请使用buildplan.tasks
属性:
> mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks=clean,deploy
答案 2 :(得分:15)
一个有用的工具是mvn help:effective-pom
它将打印包含所有变量的POM,并扩展所有父POM。这有助于理解Maven看到的内容。从那里,找到所有额外的目标(通常不是那么多)非常简单。
更大的问题是隐含目标(即当插件自动挂钩到生命周期的某些阶段时)。没有实际运行Maven就没有简单的方法可以看到这些。这应该在Maven 3中变得更好。在那之前,使用-X
运行Maven,它将打印大量的调试输出加上当前阶段以及执行哪些插件。
答案 3 :(得分:1)
如果没有Maven但是使用m2e你可以使用你可以在Eclipse插件中使用的代码块来实现它:
final IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();
final IMavenProjectFacade facade = projectRegistry.getProject(project);
projectRegistry.execute(facade, new ICallable<Void>() {
public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = facade.getMavenProject(monitor);
List<MojoExecution> mojoExecutions = ((MavenProjectFacade) facade).getMojoExecutions(monitor);
LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(
mavenProject, mojoExecutions, facade.getResolverConfiguration().getLifecycleMappingId(),
monitor);
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mojoExecutionMapping = mappingResult
.getMojoExecutionMapping();
Map<String, List<MojoExecutionKey>> phases = new LinkedHashMap<String, List<MojoExecutionKey>>();
for (MojoExecutionKey execution : mojoExecutionMapping.keySet()) {
List<MojoExecutionKey> executions = phases.get(execution.getLifecyclePhase());
if (executions == null) {
executions = new ArrayList<MojoExecutionKey>();
phases.put(execution.getLifecyclePhase(), executions);
}
executions.add(execution);
}
查看完整source。
已实施于:
http://marketplace.eclipse.org/content/phases-and-goals
它利用m2e计算目标与阶段关联的能力。我也试图在maven级解决它。
答案 4 :(得分:1)
我把Chad的答案放到一个脚本中(所以我不必记住插件名称真的很长)。把它放在〜/ bin /文件夹中,这样你就可以在任何地方使用它。
main.c: In function 'main':
main.c:23:9: error: expected expression before 'int'
main.c:25:33: error: invalid operands to binary + (have 'int (*)()' and 'int (*)
main.c:25:58: error: expected expression before 'int'
^
main.c:27:33: error: invalid operands to binary + (have 'int (*)()' and 'int (*)
expected identifier or '(' before '{' token