I'm trying to exclude a single test from my maven build (I don't want the test to be compiled or executed). The following doesn't work:
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/MyTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
What is the correct way to achieve my goal? I know that I can use the command-line option -Dmaven.test.skip=true
, but I would like this to be part of the pom.xml
.
Skip the test
From the docs, if you want to skip a test, you can use:
See the diference, in your example, you use
<artifactId>maven-compiler-plugin</artifactId>
, and the docs say that you shoul use<artifactId>maven-surefire-plugin</artifactId>
plugin instead.And, if you want to disable all test, you can use:
Also, if you are using
JUnit
, you can use @Ignore, and add a message.Exclude the test from compilation
From this answer, you can use. The trick is intercept the
<id>default-testCompile</id> <phase>test-compile</phase>
(default test compile phase) and exclude the class:The simplest way of skipping the compilation and execution of test by default in Maven is to add the following property in your
pom.xml
:You still can change the behavior by override the property from the command-line:
Or by activating a profile: