Run JUnit tests for Maven reactor nested sub-sub-m

2019-06-09 23:24发布

问题:

I'm working with a deeply nested Maven reactor project:

  • root pom.xml specifies a module dspace
  • module dspace's pom.xml specifies a module modules
  • module modules's pom.xml specifies (among others) a module rest

So there is a nested module hierarchy: dspace -> modules -> rest.

I have written JUnit tests for (sub-sub-)module rest and would like to execute them. If I run mvn test -pl rest, Maven fails:

[INFO] Scanning for projects...
[ERROR] [ERROR] Could not find the selected project in the reactor: rest @
[ERROR] Could not find the selected project in the reactor: rest -> [Help 1]

How can I execute tests in nested Maven modules?

回答1:

Pretty easy: mvn test -pl dspace/modules/rest

(or when tests are deactivated by default, as it is the case with the example DSpace Maven project: mvn -Dmaven.test.skip=false test -pl dspace/modules/rest )



回答2:

I was having the same problem for my multi module maven application. I am able to run the JUnit test case from root directory by issuing the below maven command. My Multi module project structure is something like this.

  • Custom-Service (Parent Module)
    • Model-API (Sub-Module)
    • Model-Impl (Sub-Module)
    • WebServices (Sub-Module)

I want to run JUnit test case inside Model-Impl module.

mvn -DfailIfNoTests=false -Dtest=MyTest clean install -pl Model-Impl -am



标签: maven junit