Home > OS >  How to exclude src/test/java from being compiled by Maven
How to exclude src/test/java from being compiled by Maven

Time:12-02

For our release build, I'd like to exclude src/test/java from being compiled in order to increase performance.

We're already using 'skip tests' so the tests aren't being executed but I can see in the logs that they are being compiled. The tests are already being run by another build in Gitlab which this build depends on so it is safe to not even compile the tests in this case.

I can see how to add a source folder via Build Helper Maven Plugin but cannot see how to exclude one.

Anyone know how to exclude src/test/java from compilation?

CodePudding user response:

To skip tests there are two different ways to do so.

Using:

mvn -DskipTests ...

this will set the skipTests property which will prevent the execution of the tests but will still compile those tests.

The next one is:

mvn -Dmaven.test.skip=true ...

this will set the maven.test.skip property which will prevent both. The execution of the tests and also the compilation of the test code.

Details can be found in the documentation:

  • Related