Here it is stated:
since Maven 3.0.3, for two plugins bound to the same phase, the order of execution is the same as the order in which you define them
I'm using Maven 3.3.9 and I can see that execution order is NOT ALWAYS defined by order of plugins in the POM.
I have the following plugins bound to Maven lifecycle phases:
pre-integration-test: maven-resources-plugin, 3.0.1 - prepares certain files
integration-test: maven-failsafe-plugin, 2.19.1 - runs Cucumber-jvm tests
post-integration-test: exec-maven-plugin (id: cleaner), 1.5.0 - stops certain processes
maven-cucumber-reporting, 2.4.0 - generates rich HTML report
exec-maven-plugin (id: converter), 1.5.0 - converts rich HTML report to a light version
The three plugins bound to the "post-integration-test" phase are listed here in the order they are defined in the POM. If all tests pass without errors (at the "integration-test" phase) - these plugins are executed as expected: in the order they are defined in the POM. But if any of the tests fail - then I get the following situation:
- 3rd plugin is run first - "exec-maven-plugin (id: converter)". It doesn't find the "rich HTML report" to convert and fails.
- After that the 2nd plugin runs - "maven-cucumber-reporting". It successfully generates the "rich HTML report".
- And the 1st plugin - "exec-maven-plugin (id: cleaner)" - never gets run.
One strange thing more: although "maven-cucumber-reporting" plugin generates rich HTML report successfully, I see the following in the log file: "Failed to execute goal maven-cucumber-reporting:2.4.0:generate (execution) on project ...: Error Found: BUILD FAILED".
If I comment out 2nd and 3rd plugins in the POM - then the remaining plugin ("exec-maven-plugin (id: cleaner)") runs successfully. In this case I see the following in the log file: "Failed to execute goal maven-failsafe-plugin:2.19.1:verify (default) on project ...: There are test failures". Well, this message is quite expected.
QUESTION: Why plugins bound to the same phase are not executed in the order they are defined in the POM (but only when previous phase has failed)?