In this short Maven tutorial, you will learn how to build or run a Maven project and skip Unit tests.
Sometimes, when working on a project we need to build it and even run it even though our Unit test is failing. When there is a flailing Unit test, then the Maven package and install commands will also fail. This is because both of these commands execute Unit tests.
To skip Unit tests when building a Maven project use one of the following ways.
Skip Unit Test With -Dmaven.test.skip=true
One of the ways to skip Unit tests when building a Maven project is to use -Dmaven.test.skip=true. For example, to package a maven project without running Unit tests you will issue the following command:
mvn package -Dmaven.test.skip=true
or if you use Maven Install, then:
mvn install -Dmaven.test.skip=true
Alternatively, to using -Dmaven.test.skip=true in a terminal window when running a specific Maven command, you can disable Unit tests for all Maven commands. To disable Unit tests using POM.XML add maven.test.skip to properties XML element.
<properties> <maven.test.skip>true</maven.test.skip> </properties>
If You Use maven-surefire-plugin
If you use maven-surefire-plugin then when running the Maven command in the terminal window you can skip Unit tests the following way:
mvn package -DskipTests
or if you use Maven install then,
mvn install -DskipTests
Alternatively, to using -DskipTests in a terminal window when running a command you can configure to skip Unit tests in POM.xml file this way:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M3</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin>
I hope this tutorial was helpful to you.
If you want to learn more about Maven, and you enjoy learning by following a series of step-by-step video lessons, then have a look at the below list of video courses which teach Maven.
I hope this short Android tutorial was helpful.