Search code examples
javamavenintegration-testingmaven-failsafe-plugin

Should maven-failsafe-plugin be executed in descendants of POM where it is specified?


I've specified the use of Failsafe in a parent POM. When I run mvn verify on my multi-module build, there is no hint of Failsafe being run - it appears nowhere in the console output.

If I add the same <plugin> definition into a child POM, it does get run (although it complains about not being able to find \failsafe-reports\failsafe-summary.xml).

Surely it should be inheriting which plugins are to be run?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.15</version>
    <executions>
        <execution>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Solution

  • First you should define it in pluginManagement like this:

      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-failsafe-plugin</artifactId>
              <version>2.15</version>
              <executions>
                <execution>
                  <id>integration-test</id>
                  <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    

    The important part is to use the goals integration-test and verify and not only verify. Aaprt from the above you need to define the real usage like this:

    <project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
    

    You can activate the usage separately in every sub-module you would like to use integration tests by adding the above snippet. This is usually only in a few modules the case.