user373201
user373201

Reputation: 11435

Maven - How to compile tests without running them ?

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.

Upvotes: 197

Views: 125294

Answers (7)

orange77
orange77

Reputation: 1103

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

mvn test-compile

Upvotes: 61

Stephan
Stephan

Reputation: 43013

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.

Upvotes: 10

lweller
lweller

Reputation: 11317

you can try to use parameter -DskipTests

References:

Upvotes: 28

schnatterer
schnatterer

Reputation: 7859

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.

Upvotes: 2

Martins
Martins

Reputation: 1261

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.

Upvotes: 39

RonU
RonU

Reputation: 5785

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.

Upvotes: 442

menapole
menapole

Reputation: 1178

If you settings.xml file you can also use

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

Upvotes: 0

Related Questions