How to run tests only for a single Maven module?

Viewed 427

Given a Maven project with modules dad and son, where son depends on dad, mvn -am -pl son test runs the tests for dad too. Is there a way to avoid this and only run tests for son module?

Note that there a couple of ways to achieve this, though each has its own caveats which I don't prefer:

  • Using -Dtest="**/son/*Test.java" -DfailIfNoTests=false overrides the maven-surefire-plugin config in the module.
  • Similar to -Dtest, JUnit 5 tags could also be filtered, but this approach suffers from the same shortcoming aforementioned.
  • One can first do an install -DskipTests=true and then mvn -pl son test, though this pollutes the local Maven repository with partial work.
0 Answers
Related