Maven: surefire plugin ignores -Dgroups when <groups> is already configured
There are several JUnit tests in my project that I rarely want to run. For this, I put them in @Category , and then I did this:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <!-- Run all but the inject tests --> <configuration> <groups>!be.test.InjectTests</groups> </configuration> </plugin> I would like to redefine the configuration on the command line to run Inject tests as follows:
mvn clean install -Dgroups=be.test.InjectTests But this does not work, -Dgroups are ignored by Maven.
If I donβt, the team works great.
+4
1 answer
Unfortunately, it seems that if something is installed in pom, it is not easy to override (if you set skipTests explicitly, it would be difficult to override the property skipTests ) ... But! (and this is a bit of a hack), you can defer property setting to the pom property and then override it on the command line.
<project> ... <properties> <groups>!Slow</groups> <properties> .... <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.13</version> <configuration> <groups>${groups}</groups> </configuration> </plugin> </plugins> </build> ... With this (and a fast-track project running on OSX, Maven 3.0.4, Java 1.6.0_37):
$ mvn clean test ... Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 ... $ mvn clean test -Dgroups=Slow ... Results : Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 +5