Maven build second level+ child projects using rea

2020-05-25 06:16发布

My maven project structure is as below

Project A 
  pom.xml
  - ProjectB
    pom.xml
    - ProjectC
      pom.xml
    - ProjectD
      pom.xml
  - ProjectY
    pom.xml

By using maven reactor options i can

clean install -pl projectB or clean install -pl projectY

But while trying to build the second level child modules using clean install -pl projectC, maven throws

org.apache.maven.MavenExecutionException: Could not find the selected project in the reactor: projectC

how to build the second level+ child modules using maven reactor options

标签: maven
3条回答
狗以群分
2楼-- · 2020-05-25 06:45

Just in case someone else has this one too:

I also encountered this error message. The reason was that by accident I had been in one of my (sub-)modules in the path in terminal.

Of course the command has to be executed in the project's root hierarchy. According to the example above you have to assure that you execute a command like:

clean install -pl projectB
at Poject A

not e.g. at ProjectY or somewhere else deeper in the project structure.

Correct:

user:~/workspace/IdeaProjects/pojecta{master}$ clean install -pl projectB

Wrong:

user:~/workspace/IdeaProjects/pojecta/projecty{master}$ clean install -pl projectB
查看更多
Melony?
3楼-- · 2020-05-25 06:47

From the documentation for the -pl option it states the following:

-pl,--projects <arg>                Comma-delimited list of specified
                                    reactor projects to build instead
                                    of all projects. A project can be
                                    specified by [groupId]:artifactId
                                    or by its relative path.

The important part for you is: "or by its relative path".

So to build projectC, you simply need to refer to it by its relative path (projectB/projectC). So the command you need is:

mvn clean install -pl projectB/projectC
查看更多
家丑人穷心不美
4楼-- · 2020-05-25 07:04

This is an answer from a similar question that is also relevant here.
By using artifactIds you don't have to know the structure of your project.


If you only use the artifactIds of the given project you have to define that correctly on command line:

help output of Maven (mvn --help)

Comma-delimited list of specified reactor projects to build of all projects. A project can be specified by [groupId]:artifactId or by its relative path

This means in your case you have to define:

mvn clean install --projects :projectC,:ProjectY

Notice the : that is prepended to the artifactIds to indicate you omit the groupId

查看更多
登录 后发表回答