Maven - How to compile tests without running them ?

Maven

Maven Problem Overview


Is there a way in Maven to compile the tests without running them ? I want to use the IDE to run specific tests and not all of them.

Maven Solutions


Solution 1 - Maven

How about the test-compile lifecycle phase? It doesn't require any test skipping, because it occurs before the test phase. I.e.,

$ mvn test-compile

And done.

Introduction to the Build Lifecycle explains further.

Solution 2 - Maven

To just compile the tests and code, without running them, just do:

mvn test-compile

Solution 3 - Maven

When executing a goal that will include the testing phase (such as package), you can do two things:

  • Use the command mvn -DskipTests=true package. This will compile all tests but not run them.
  • Or mvn -Dmaven.test.skip=true package. This will not compile or run the test branch.

Solution 4 - Maven

you can try to use parameter -DskipTests

References:

Solution 5 - Maven

Alternatively, you can use maven.test.skip.exec option.

mvn -Dmaven.test.skip.exec=true

Maven will compile the tests without running them. I use this option in all my projects regularly.

Solution 6 - Maven

In case you really want to only compile the tests (skip all other phases like compile), this will do

mvn org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile

See the plugin bindings of the default lifecycle.

Solution 7 - Maven

If you settings.xml file you can also use

<maven.test.skip>true</maven.test.skip>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser373201View Question on Stackoverflow
Solution 1 - MavenRonUView Answer on Stackoverflow
Solution 2 - Mavenorange77View Answer on Stackoverflow
Solution 3 - MavenMartinsView Answer on Stackoverflow
Solution 4 - MavenlwellerView Answer on Stackoverflow
Solution 5 - MavenStephanView Answer on Stackoverflow
Solution 6 - MavenschnattererView Answer on Stackoverflow
Solution 7 - MavenmenapoleView Answer on Stackoverflow