2

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)?

Community
  • 1
  • 1
Alexey Y.
  • 123
  • 8
  • 1
    can you share the releavent `pom.xml` part? – A_Di-Matteo Jul 25 '16 at 08:33
  • This is potentially related to [this SO q/a](http://stackoverflow.com/questions/37434109/maven-run-plugin-twice-during-a-phase-interleaved-with-another-plugin). About "these plugins are executed as expected", are you sure about that? – A_Di-Matteo Jul 25 '16 at 08:39
  • This part is about 6000 symbols - too long for this comment. And attachments are not allowed here. Yes, when all tests pass without errors - these plugins are executed as expected: in the order they are defined in the POM. – Alexey Y. Jul 25 '16 at 08:51
  • please add the relevant parts of your `pom.xml` to the **question** (via `edit`) , not in a comment – JimHawkins Jul 25 '16 at 09:36
  • I read the link. They say we cannot define same plugin twice in the same POM. So I changed binding: 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 verify: exec-maven-plugin (id: converter), 1.5.0 - converts rich HTML report to a light version – Alexey Y. Jul 25 '16 at 09:37
  • Now there is only ONE definition of the exec-maven-plugin, but it has TWO executions bound to different phases. Well, I got another problem now: the 2nd execution (bound to the "verify" phase) is not executed. – Alexey Y. Jul 25 '16 at 09:43
  • How do you call Maven? – khmarbaise Jul 31 '16 at 09:37

1 Answers1

2

Well, I found the answer myself. Having two definitions of the same plugin (exec-maven-plugin) is only part of the problem: it explains the wrong order of execution but doesn't explain why cleaner is never run. The latter problem has the following explanation: maven-cucumber-reporting plugin has code which prevents execution of all further phases of the Maven lifecycle if the build has failed previously. Fortunately, this code can be disabled in parameters - see this issue at GitHub for details.

Alexey Y.
  • 123
  • 8