javamavengauge

Two Maven plugin with same execution phase


Is it possible to execute same life cycle of two maven plugin if one fails ?

Example:

Let's say I have below plugin configuration,

<plugins>
  <plugin>
    <groupId>smothing</groupId>
    <artifactId>plugin-1</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
        <id>doSomthing</id>
        <phase>test</phase>
        //...//
  </plugin>

  <plugin>
    <groupId>something</groupId>
    <artifactId>plugin-2</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
        <id>doSomthingAgain</id>
        <phase>test</phase>
        //...
  </plugin>
</plugins>

I would like to execute plugin-2 test phase even if the first plugin fails. I don't want to ignore or skip test cases.

I have below two plugin to be executed same phase even if one fails.

<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>

<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>

Basically, after the gauge tests I want to perform some cleanup activities through maven exec plugin. So is there any option for me to always execute maven exec plugin ? (No command line arguments, something which I am expecting in pom.xml )

I have seen these answers, but everything says to skip test cases.

How to run a maven goal when there is tests failures?

Maven reporting plugins do not execute if a unit test failure occurs

Any help much appreciated :)


Solution

  • If a plugin fails, it'll stop the execution of the lifecycle. So you shouldn't try to solve it by thinking of executing another plugin for some condition. Based on your description the best approach seems to be writing an extension, see https://maven.apache.org/examples/maven-3-lifecycle-extensions.html . With https://maven.apache.org/ref/3.6.0/maven-core/apidocs/index.html?org/apache/maven/execution/AbstractExecutionListener.html you can see that you can do actions before or after any segment of the lifecycle, e.g. cleaning up after projectSucceeded+projectFailed