Maven skip tests

11 points
Created by:

Most communly used command:

$ mvn clean install -Dmaven.test.skip=true

1. Overview

In this post we will see how to skip unit tests when we build our project with maven.

Easiest way to skip unit tests with maven is by using one of the commands:

$ mvn clean install -Dmaven.test.skip=true
# or
$ mvn install -Dmaven.test.skip=true


$ mvn clean package -Dmaven.test.skip=true
# or
$ mvn package -Dmaven.test.skip=true

Example of maven clean command:

# before running install or package, run clean to clear target directory
$ mvn clean

Sometimes we may want to build our project without running all unit tests again.

Or some of the unit tests are failing and we want to build the jar anyway.

There is more then one way to accomplish it.

Maven -D parameter means - define a system property, from mvn -help command.

Maven - skip unit tests screenshot with Console output of maven command: mvn package -Dmaven.test.skip=true - link to post:
Console output of maven command: mvn package -Dmaven.test.skip=true

2. Skip unit tests with -Dmaven.test.skip=true

We can run maven commands with defined system property:


Below we have examples with mvn install and mvn package.

2.1 mvn install

$ mvn install -Dmaven.test.skip=true
# our build will execute without unit tests

2.2 mvn package

$ mvn package -Dmaven.test.skip=true
# our build will execute without unit tests

NOTE: maven.test.skip is honored by:

  • Maven Surefire Plugin
  • Maven Failsafe Plugin
  • Maven Compiler Plugin

3. Disable unit tests permanently in pom.xml

Add this property to pom.xml


When we have this property defined in our pom.xml, we can run

$ mvn install
# our build will execute without unit tests


$ mvn package
# our build will execute without unit tests

Maven will accept property from pom.xml and skip running unit tests.

4. If we use Maven Surefire Plugin

Add this xml property to Maven Surefire Plugin configuration in pom.xml:


Full pom.xml example, where we need to add this configuration to skip unit tests:


        <!-- HERE it goes -->


5. Maven -D parameter mean - explanation

What does maven -D parameter mean?
It means - define a system property.

-D, --define <arg>

To define property we need to use -D.
Synonym of '-D' parameter is '--define'


$ mvn install -DskipTests=true
$ mvn install -DfailIfNoTests=false

When we execture mvn -help, we will get description of all flags.

$ mvn -help
-D, --define <arg>  Define a system property

6. mvn diff between clean install vs clean package

mvn clean - will remove our target directory

mvn install - will build our jar + put it into target dir and copy it to maven .m2 repository on our PC, example of maven local repository path:


mvn package - will build our jar + put it into target dir, nothing more and nothing less

From maven documentation:

  • install - install the package into the local repository, for use as a dependency in other projects locally
  • package - take the compiled code and package it in its distributable format, such as a JAR.

7. Maven clean - why to run it?

It is good practice to run maven clean command before running mvn install or mvn package command. Maven clean will remove our target directory and in that way we will ensure our code and resources are freshly compiled to target directory.

Merged questions

  1. Maven - how to skip unit tests
  2. How do I skip tests with maven?
  3. mvn skip unit tests
  4. mvn clean install skip test
  5. mvn package skip test


  1. Maven Surefire Plugin - skipping tests
  2. Maven Failsafe Plugin - skipping tests
  3. Maven Compiler Plugin
  4. Introduction to the Standard Directory Layout
  5. Introduction to the Build Lifecycle
Native Advertising
50 000 ad impressions - 449$
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂