I'm just learning Maven, and so this might be obvious, but I can't find an easy way to list the goals associated for each maven lifecycle phase for a given project.
I saw that the Maven default life cycle phases and corresponding default goals are documented here. My understanding so far is that each pom.xml can bind additional goals to each lifecycle phase.
So, is there a mvn command to determine the goals that will be run for each lifecycle phase for a given project? If not, I guess I just have to look through the pom.xml for each new maven project to figure this out?
One tool that helps is
mvn help:effective-pom
It will print the POM with all variables and all parent POMs expanded. This helps to understand what Maven sees. From that, it's pretty simple to find all the additional goals (which usually aren't that many).The bigger problem is the implicit goals (i.e. when a plugin hooks itself to some phases of the lifecycle automatically). There is no easy way to see these without actually running Maven. This should become better in Maven 3. Until then, run Maven with
-X
which will print a whole lot of debug output plus the current phase and which plugins are executed.If not with Maven but using m2e you can do it using the code block that you can use in a Eclipse plugin:
Look at full source.
Already implemented in:
http://marketplace.eclipse.org/content/phases-and-goals
It makes use of m2e's ability to compute the association of goals with phases. I am also trying to solve it at maven level.
The
buildplan-maven-plugin
is an excellent tool for showing how goals are bound to phases.Below are examples of commands you can run. The commands will automatically download and install the plugin if it hasn't already been installed.
List goals by the order they will execute
Group goals by phase
Group goals by plugin
Notes
By default, the goals search for tasks that would run if the user invoked
mvn deploy
. Phases such asclean
won't be included. To include multiple phases in the search, use thebuildplan.tasks
property:mvn help:describe -Dcmd=compile
(or any other valid phase)I put Chad's answer into a script (so I don't have to remember the plugin name which is really long). Put it in your ~/bin/ folder so you can use it anywhere.