Search code examples
mavenmaven-3maven-pluginmaven-surefire-plugin

Maven command to exclude nothing despite exclude entry in pom


Which maven command can be used to execute all tests despite there is <exclude> entry under surefire plugin configuration in pom.xml file?

For example - Following is section from pom.xml but i do not want to exclude TestA.java. Which maven command can be used?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <excludes>
        <exclude>**/TestA.java</exclude>
    </excludes>
 </configuration>
</plugin>

Solution

  • Add a profile to your pom.xml

    <profiles>
        <profile>
            <id>all-tests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude></exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

    This profile overwrites the excludes section for surefire plugin. Simply activate the profile via:

    mvn clean install -Pall-tests