Maven skip tests

ID : 10241

viewed : 55

Tags : mavenmaven

Top 5 Answer for Maven skip tests

vote vote


As you noted, -Dmaven.test.skip=true skips compiling the tests. More to the point, it skips building the test artifacts. A common practice for large projects is to have testing utilities and base classes shared among modules in the same project.

This is accomplished by having a module require a test-jar of a previously built module:

<dependency>   <groupId>org.myproject.mygroup</groupId>   <artifactId>common</artifactId>   <version>1.0</version>   <type>test-jar</type>   <scope>test</scope> </dependency> 

If -Dmaven.test.skip=true (or simply -Dmaven.test.skip) is specified, the test-jars aren't built, and any module that relies on them will fail its build.

In contrast, when you use -DskipTests, Maven does not run the tests, but it does compile them and build the test-jar, making it available for the subsequent modules.

vote vote


I had some inter-dependency with the tests in order to build the package.

The following command manage to override the need for the test artifact in order to complete the goal:

mvn -DskipTests=true  package 
vote vote


There is a difference between each parameter.

  • The -DskipTests skip running tests phase, it means at the end of this process you will have your tests compiled.

  • The -Dmaven.test.skip=true skip compiling and running tests phase.

As the parameter -Dmaven.test.skip=true skip compiling you don't have the tests artifact.

For more information just read the surfire documentation:

vote vote


To skip the test case during maven clean install i used -DskipTests paramater in following command

mvn clean install -DskipTests 

into terminal window

vote vote


I can give you an example which results in the same problem, but it may not give you an answer to your question. (Additionally, in this example, I'm using my Maven 3 knowledge, which may not apply for Maven 2.)

In a multi-module maven project (contains modules A and B, where B depends on A), you can add also a test dependency of A in B.

This dependency in B may look as follows:

<dependency>      <groupId></groupId>      <artifactId>A</artifactId>      <classifier>tests</classifier>      <type>test-jar</type> <!-- I'm not sure if there is such a thing in Maven 2, but there is definitely a way to achieve such dependency in Maven 3. -->      <scope>test</scope> </dependency> 

(For more information refer to

Note that project Ausually produces a secondary artifact with a classifier tests (i.e. .../com/foo/A/<version>/A-<version>-tests.jar) where the test classes and test resources are located inside.

If you build project A with -Dmaven.test.skip=true, you will get a dependency resolution error when building B unless A's test artifact is found in your local repo or remote repositories. The reason is that the test classes of A were neither compiled nor the tests artifact of A was produced.

However, if you build A with -DskipTests its tests artifact will be produced (though the tests won't run) and the dependency in B will be resolved successfully.

Top 3 video Explaining Maven skip tests