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 themaven-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 thenmvn -pl son test
, though this pollutes the local Maven repository with partial work.
mvn install
fordad
is the idiomatic way with Maven for this type of work. Though you also have an option to run them from IDE :) – Net-am
cause it says:If project list is specified, also build projects required by the list
...... Why do you do such things on command line and not within your ide? Apart from that what is so problematic to use theinstall ..
andmvn -pl son test
approach? So your local repository can be cleaned up easy? ...Running tests from a module or parts of it ... just using the IDE ... never doing that on command line ... the CI runs all tests on my branches... – Officer~/.m2
with partial work just to run the tests of a single module doesn't sound idiomatic to me. – Cachedad
, though if you don't provide-am
to compile the dependency modules, Maven complains thatdad
is not found. – Cache$HOME/.m2/repository
is a cache nothing else... polluting? There are then SNAPSHOT's etc.. So what? – Officermvn install
for the whole project. Than you can usemvn -pl son
from the root which will resolve the dependency from your local cache... – Officerlog4j-layout-template-json
module due to its complex setup. Hence, it is not an option always. Thanks for your kind alternative work arounds, though in the question I explicitly stated that I want to avoidinstall
and want to do this usingmvn
, not an IDE. – Cacheinstall
but you do ??? – Officer