When maven projects trying to package jar or war file, It compiles test classes execution by default.
This tutorial explains multiple ways to disable test case execution in maven projects.
maven package
It compiles java and test source files, executes test files, and packages the source code as per configured module.
Maven skip test case execution
There are multiple ways to disable test case execution
using command line Maven has below JVM command line arguments to mvn command.
maven.test.skip.exec=true : This compiles test java files, but does not execute test cases
-Dmaven.test.skip=true
This disables compilation and test case execution and does not generate test-jar artifacts in the target folder.
-DskipTests
- It is a shorthand argument in place of -Dmaven.test.skip=true
Here is an example of command usage for package goal
mvn package -Dmaven.test.skip=true
or
mvn package -DskipTests
For mvn clean install command
mvn clean install -Dmaven.test.skip=true
or
mvn clean install -DskipTests
- using the pom.xml plugin maven-surefire-plugin configuration contains skipTests property, change to true to disable test case execution
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
- pom.xml properties
You can add maven.test.skip property in properties of pom.xml to skip test cases at the project or module level.
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>