Does the Maven team list lifecycle phases along with related goals?

I am just learning Maven, and so this may be obvious, but I cannot find an easy way to list the goals associated for each phase of the maven life cycle for a given project.

I have seen that the default Maven life cycle phases and associated default goals are documented here . So far, I understand that every pom.xml can attach additional goals to each phase of the life cycle.

So, is there an mvn command to determine the goals that will be executed for each phase of the life cycle for a given project? If not, I think I just need to look at pom.xml for each new maven project to figure this out?

+67
maven-2
Nov 10 '09 at 17:16
source share
4 answers

mvn help:describe -Dcmd=compile (or any other valid phase)

+97
Jan 14
source share

buildplan-maven-plugin is a great tool to demonstrate how goals relate to steps.

The following are examples of commands that you can run. Teams will automatically download and install the plugin if it is not already installed.

A list of goals in order that they will fulfill

 > 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 

Group Goals by Phase

 > 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 

Plugin Group Goals

 > 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 

Notes

By default, searching for goals for tasks that will be executed if the user calls mvn deploy . Phases such as clean will not be included. To include several phases in the search, use the buildplan.tasks property:

 > mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list -Dbuildplan.tasks=clean,deploy 
+45
Feb 24 '16 at 18:41
source share

One tool that helps is mvn help:effective-pom It will print POM with all variables and all parent POM extensions. This helps to understand what Maven sees. From this it is quite easy to find all the additional goals (which are usually not so many).

Implicit goals are a bigger problem (for example, when a plug-in automatically connects to some stages of the life cycle). There is no easy way to see them without actually launching Maven. This should get better in Maven 3. Until then, start Maven with -X , which will print a lot of debug output plus the current phase and which plugins are running.

+13
Nov 10 '09 at 17:24
source share

If you are not using Maven but using m2e, you can do this using a block of code that you can use in the Eclipse plugin:




 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); } 



Look at the full.

Already implemented in:

http://marketplace.eclipse.org/content/phases-and-goals

It uses m2e's ability to calculate the phase integration of targets. I am also trying to solve this at the maven level.

+1
Jul 17 '15 at 4:43
source share



All Articles