Search code examples
javamavenpitest

Skip running PITest in maven build


I'm trying to run a maven build from command line and exclude PITest from running any mutations. Currently the reports are failing and we need to be able to give a parameter to ignore running the mutation tests or ignore the results and continue the build

I've running with some parameters like mvn package -Dpit.report=true

or mvn package -Dmaven.report.skip=true

This is the PITest setup in my pom

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.1.10</version>
    <configuration>
        <timestampedReports>false</timestampedReports>
        <mutationThreshold>95</mutationThreshold>
    </configuration>
    <executions>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>mutationCoverage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The problem is that is is still running PITest and causing the build to fail


Solution

  • There is no native way of skipping a plugin execution, but there are least 2 workarounds:

    • First, is adding a property to override execution phase:

    Define a property pitPhase with default value as the default phase of plugin execution.

    Then in plugin configuration:

    <execution>
       <phase>${pitPhase}</phase>
       ...
    </execution>
    

    After that, when you want to skip execution mvn -DskipPit=pitPhase package

    • The other alternative is to add a Maven profile with the plugin execution