Install parent POM without building Child modules

2019-03-08 02:33发布

I have a parent POM in a Maven project, with this structure:

             parent
               |
        ---------------
        |             |
      child1       child2

I want to install the POM of the "parent" in the local REPO to allow child1 take some changes that I did in the dependencyManagement, but I cannot do a regular "clean install" because "child2" is broken and will not build.

Which is the proper way to do this with maven (other than going to the parent pom and commenting the "child2" module).

2条回答
闹够了就滚
2楼-- · 2019-03-08 03:21

Use the '-N' option in the mvn command.

From mvn -h:

-N,--non-recursive Do not recurse into sub-projects

查看更多
孤傲高冷的网名
3楼-- · 2019-03-08 03:25

While Guillaume is indeed right and that is the correct option, I would personally recommend keeping your parent as a separate module.

I find the best approach for inheritance to be as follows:

aggregator
|- module1/ (extends parent)
| |- pom.xml
|- module2/ (extends parent)
| |- pom.xml
|- parent/
| |- pom.xml
|- pom.xml

This way you can always install the parent only, with mvn clean install without extra options.

You can also have the parent outside the aggregator so you can re-use it between more projects.

There are numerous benefits to keeping the parent and the aggregator as two separate things. But in the end, you choose what's best for your project/environment.

查看更多
登录 后发表回答