I am new to Maven and I understand that the convention is mvn pluginId:goalId
. So when we run mvn compiler:compile
we are running the goal compile
of the compiler
plugin.
But it is not clear to me what mvn package
as it does not follow the convention. It seems to be able to run a stage directly.
I checked to see if I can find a plugin that offers package
as a plugin (I made the assumption that maybe the plugin somehow is assigned automatically) so googling I found this command:
mvn help:describe -Dcmd=package
and when I run it I get:
It is a part of the lifecycle for the POM packaging 'jar'. This lifecycle includes the following phases:
* validate: Not defined
* initialize: Not defined
* generate-sources: Not defined
* process-sources: Not defined
* generate-resources: Not defined
* process-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:resources
* compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
* process-classes: Not defined
* generate-test-sources: Not defined
* process-test-sources: Not defined
* generate-test-resources: Not defined
* process-test-resources: org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
* test-compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
* process-test-classes: Not defined
* test: org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
* prepare-package: Not defined
* package: org.apache.maven.plugins:maven-jar-plugin:2.4:jar
* pre-integration-test: Not defined
* integration-test: Not defined
* post-integration-test: Not defined
* verify: Not defined
* install: org.apache.maven.plugins:maven-install-plugin:2.4:install
* deploy: org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
Since I see
* compile: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
I thought I can find the name for the plugin that offers the package goal.
So using
* package: org.apache.maven.plugins:maven-jar-plugin:2.4:jar
I run
mvn jar:package
but I am getting an error.
So I am confused. What exactly is package
in mvn package
?
It seems it is neither a pluginId (this command mvn help:describe -Dplugin=package
also fails) nor a goal?
package
is not the name of a goal. It is the name of a phase. When you run mvn package
, all the goals bound to the package
phase will be run.
From the output, the org.apache.maven.plugins:maven-jar-plugin:2.4:jar
goal (aka jar:jar
) is bound to the package
phase. Running mvn package
will run the jar:jar
goal, along with whatever other goals are bound to that phase.
Similarly, compile
is also the name of a phase. The org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
goal (aka compiler:compile
) is bound to it. It just so happens that the name of the goal is the same as the name of the phase.
jar:package
is not a goal.
See the tables towards the end of this documentation page to see a list of the default bindings.