Issue
I noticed maven plugins has goals and they are bound to different phases. But it seems some goals will only be executed after we explicitly config them in side execution
tag. For example, maven-jar-plugin has two goals jar
and test-jar
. If you don't config test-jar
goal explicitly inside execution
tag then it will not be executed. It will only be triggered with below config where test-jar
is explicitly config inside execution
tag
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
But for goal jar
whether you config it with execution
tag or not, it will always be triggered. In this case, I wonder to trigger a goal of a plugin should we config it inside execution
tag or not? I didn't see official doc has any clarification on this either. Thanks.
Solution
The jar
goal is by default bound to the default life cycle (jar) so it's triggered automatically
.
All plugins which are bound by the default life cycle (for example maven-compiler-plugin etc) will run automatically during a build.
Any other goals which are not bound will not run automatically and have to be bound manually if needed.
All goals like the jar
goal of the maven-jar-plugin should never being bound manally... because they are already bound to the life cycle.
Furthermore you should always check the documentation of the appropriate plugin (here the maven-jar-plugin) and check the goal page for the text: Binds by default to the lifecycle phase: package.
This means you can omit the <phase>..</phase>
part of your configuration because the plugin knows the life cycle phase when it should start.
Answered By - khmarbaise
Answer Checked By - Marie Seifert (JavaFixing Admin)