Ignore module during maven build for maven multi-module project

Is it possible to run the maven test build ( mvn clean test ) in a project with several maven modules and skip / ignore a specific module test? for example -Dmaven.test.skip=true , but for a specific module, and not for all modules? I do not want to change the correct <configuration> to enable <skipTests>true</skipTests> for the module that I want to skip for tests. I wanted to know if this could be done from the command line. I need this because in my project I have many modules, and one or two are really involved in the test execution, so when I want to test only a couple of modules, I would like to skip these time modules, which I don’t have any changes.

+7
source share
2 answers

Are you sure it’s hard to change the configuration of the surefire plugin? Since you can change it once only in your module ...

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <skipTests>${skip.foo.module.tests}</skipTests> </configuration> </plugin> </plugins> </build> 

... and pass the true / false value of the skipTests tag to the maven property activated by the special profile:

 <properties> <skip.foo.module.tests>false</skip.foo.module.tests> </properties> <profiles> <profile> <id>SKIP_FOO_MODULE_TESTS</id> <properties> <skip.foo.module.tests>true</skip.foo.module.tests> </properties> </profile> </profiles> 

So that you can deactivate tests in the Foo module using the command line:

mvn clean test -P SKIP_FOO_MODULE_TESTS

+5
source

You can do this with the profile that configured surefire to skip. This will allow you to run the test most of the time, but when you want to skip tests for one of the modules someday, you can invoke this profile. You can then exclude all tests using the missed tests, or use the exceptions option to exclude only one or two tests that run for a long time.

0
source

All Articles