Actual commands executed by Maven in a phase or target

This is probably a question about Maven internals and I haven't had much luck finding and finding an answer. In a nutshell, I am interested in what Maven commands actually execute for each phase or target. For example mvn package

creates a jar file, so I think it should invoke the command jar -cf

at some point.

Maven is stubborn, so by design this command doesn't appear in the file .pom

. But which Maven commands actually perform a specific phase and purpose? Is there a way to see them?

+3


source to share


2 answers


All plugins are written in Java (or JVM languages), so if you can read them you can find out what it does. For example, here are the sources for the maven-jar-plugin: link1 , link2 .

But to get there, you need to figure out which plugins and goals are being executed when the phase starts. There are several ways:

  • In the output, Maven says what goals it serves, for example:

maven-resources-plugin: 2.6: resources (default-resources) @ module-name



  1. If you create an effective POM, you can see all the plugins and what phase they are connected: mvn help:effective-pom

    . Some plugins have phases by default, so people don't need to specify them explicitly - you will need to look at the plugin meta information or in sources to do this.
  2. Plugins and targets are by default defined by packaging. For standard packaging, you can look at default-bindings.xml (the hint role is the name of the packaging).

Once you know which plugins and targets are running, you can check the sources of each plugin (sources are usually open) and see it Mojos for the actual source code.

If you decide to examine the code, it would be helpful to be able to debug it when you run the command mvn

. For this you can use mvnDebug

instead mvn

.

Additional information: click1 , click2 .

+1


source


The call that creates the jar file is done in the maven-jar-plugin , which is associated with the lifecycle. You can do mvn -X clean package

for what goes on behind the scenes. But you won't see many commands (other than compiling javac) ... What do you mean by Maven is opinionated so by design, this command doesn't show up in the .pom file

:? lifecycles shows which phases are running bindings shows which plugins are running in that phase.

If you want to take a look at the plugin sources, all plugins can be found here: https://maven.apache.org/plugins/ On the right side, you can see links to the relevant source control system with links to it.



Each plugin has a link to the source code, for example maven-jar-plugin: https://maven.apache.org/plugins/maven-jar-plugin/source-repository.html

+1


source







All Articles