ChatGPT解决这个技术问题 Extra ChatGPT

Install parent POM without building Child modules

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).


S
Sled

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

From mvn -h:

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


The '-N' or '--non-recursive' option means do not recurse into sub-projects.
c
carlspring

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.


I struggled with this issue for hours, and found that some projects are doing this way, such as apache sling, JackRabbit and Artifactory.
It isolated maven module inheritance (dependencies, properties etc) from batch building (child modules).
Is this considered a best practice? Any blogs or other on this approach?
@ArtB Have you stumbled upon such an article in the meantime?
@MaximilianSchulz: There is no perfect world, as they say... This is just one option of doing it.