Languages
[Edit]
EN

Maven skip tests

14 points
Created by:
kaya31
526

Most communly used command:

 

1. Overview

Edit

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:

or

Example of maven clean command:

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: https://dirask.com/q/k1wL3D
Console output of maven command: mvn package -Dmaven.test.skip=true

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

Edit

We can run maven commands with defined system property:

Below we have examples with mvn install and mvn package.

2.1 mvn install

Edit

2.2 mvn package

Edit

NOTE: maven.test.skip is honored by:

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

3. Disable unit tests permanently in pom.xml

Edit

Add this property to pom.xml

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

or

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

4. If we use Maven Surefire Plugin

Edit

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:

5. Maven -D parameter mean - explanation

Edit

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

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

Examples:

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

6. mvn diff between clean install vs clean package

Edit

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?

Edit

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

Edit
  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

References

Edit
  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

Alternative titles

  1. mvn skip tests
  2. Which command is used for skipping the test in Maven?
  3. mvn clean install
  4. maven clean install
  5. mvn clean install skip tests
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Maven

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join