If you have a large multi-module project and you want to skip tests only in certain modules without having to modify each of the pom.xml module files using custom configuration and profiling, you can add the following to the parent pom.xml file:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.12</version> <executions> <execution> <id>regex-property</id> <goals> <goal>regex-property</goal> </goals> <configuration> <name>maven.test.skip</name> <value>${project.artifactId}</value> <regex>(module1)|(module3)</regex> <replacement>true</replacement> <failIfNoMatch>false</failIfNoMatch> </configuration> </execution> </executions> </plugin> </plugins> </build> <modules> <module>module1</module> <module>module2</module> <module>module3</module> </modules>
Thanks to build-helper-maven-plugin you actually dynamically check whether you are in a particular module or not during the build using the project.artifactId property (pointing to each artifactId module during build), then regex find matches for specific values (the names of the modules for which you want to skip tests) and appropriately fill the maven.test.skip property (setting it to true ).
In this case, the tests will be skipped for module1 and module3 when working properly for module2 , that is, as expressed by the regular expression.
The advantage of this approach is to make it dynamic and centralized (in the parent pom.xml ), therefore, better for maintenance: you could add or remove modules at any time simply by changing the simple regular expression above.
Obviously, if this is not the default behavior for the assembly (recommended case), you can always wrap the snippet above in the maven profile .
You can also go further and have dynamic behavior based on your input:
<properties> <test.regex>none</test.regex> </properties> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.12</version> <executions> <execution> <id>regex-property</id> <goals> <goal>regex-property</goal> </goals> <configuration> <name>maven.test.skip</name> <value>${project.artifactId}</value> <regex>${test.regex}</regex> <replacement>true</replacement> <failIfNoMatch>false</failIfNoMatch> </configuration> </execution> </executions> </plugin> </plugins> </build>
Here we actually replace the regex test.regex with the test.regex property with the default value of none (or any that would not correspond to the name of any module or, in addition, to the default skipping values).
Then from the command line we could have
mvn clean test -Dtest.regex="(module1)" > will skip tests only for module1 mvn clean test -Dtest.regex="(module1)|(module2)" > will skip tests on module1 and module2 mvn clean test -Dtest.regex="(module1)|(module2)|(module3)" > will skip the three module tests mvn clean test -Dtest.regex=".+" > will skip all module tests mvn clean test > would not skip anything (or fall back on default behavior)
That is, at runtime you decide without having to modify the pom.xml file or activate any profile.