Home / Java Patterns and Pitfalls     frequal.com

Compile Tests Without Running Them in Maven


Usually in maven you compile and run unit tests. However, in rare circumstances, you may want to compile the unit tests without running them. In those cases,use the following maven command line:
mvn compiler:testCompile


In my case, I was working on a multi-module project where I needed a module Y that depended on the tests from module X. (The act that the non-test code depended on tests from another module is a topic for another post.) Normally I would just do a full mvn clean install on module X and be done. However, the unit tests were failing so the test jar wasn't getting installed in the local repository. So to get around this problem, I needed to compile the tests, skip running the tests, and install the resulting JAR. The final command-line was:
mvn compiler:testCompile -DskipTests=true install

Last modified on 19 Oct 2015 by AO

Copyright © 2020 Andrew Oliver