Maven plugin – execution order in same phase
In Maven, you can use the build lifecycle or phases to control the order of the plugin execution. In some scenario, you have to bound few plugins to same phase, but still want to control the order of the plugin execution.
But, the order is not executed in the same order as they are listed in the POM, see this MNG-2258 and MNG-3719.
Solution
This bug is fixed in Maven 3.0.3, Maven plugin bound to same phase will be executed in the same order as they are listed in the pom.xml
For example, 3 plugins bound to the phase “prepare-package“.
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>prepare-package</phase>
//...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
//...
</plugin>
<plugin>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-optimizer-maven-plugin</artifactId>
<version>0.5</version>
<executions>
<execution>
<id>optimize</id>
<phase>prepare-package</phase>
//...
</plugin>
</plugins>
</build>
If you run mvn prepare-package
, it will execute in following sequence, just as the order they are listed in pom.xml
- maven-clean-plugin
- maven-resources-plugin
- resources-optimizer-maven-plugin
For me this works for plugins declared in the same profile, but not if some plugins are declared within a profile, others outside of profiles. Tested on Maven 3.6.3 and painfully noticed because I had a hard to diagnose problem with changing execution order of plugins within the same phase, depending on which profiles were active. See my inquiry on the Maven Users mailing list.
seems not to work for plugins in same phase, both plugins in same profile
how about the profiles in the same phase. Can this declaration order applies to there too..
You can run “mvn help:effective-pom” to see the final order, when having a profile, you should specify it “mvn help:effective-pom -PmyProfileName”