Install parent POM without building Child modules
Solution 1
Use the '-N' option in the mvn command.
From mvn -h
:
-N,--non-recursive Do not recurse into sub-projects
Solution 2
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.
Mr.Eddart
Updated on July 17, 2020Comments
-
Mr.Eddart almost 4 years
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).
-
Stéphane B. almost 12 yearsThe '-N' or '--non-recursive' option means do not recurse into sub-projects.
-
accuya over 11 yearsI struggled with this issue for hours, and found that some projects are doing this way, such as apache sling, JackRabbit and Artifactory.
-
Danubian Sailor almost 11 yearsIt isolated maven module inheritance (dependencies, properties etc) from batch building (child modules).
-
Sled almost 11 yearsIs this considered a best practice? Any blogs or other on this approach?
-
Tomislav Nakic-Alfirevic almost 10 years@ArtB Have you stumbled upon such an article in the meantime?
-
pdem about 6 yearsI have got malformed project warnings when I do this. Maven seem to discourage it.
-
Captain Man over 5 yearsI have seen this approach used on a lot of old projects in my company. It is a pain to work with. I highly discourage it. Just because Maven allows the "parent" to not be the POM that is telling it to be built doesn't mean we should use it. It makes it much harder to conceptually grasp what is going on.
-
Maximilian Schulz over 5 yearsIn my opinion, this will lead to a whole lot of other problems if you, for example, want to use this projects as a submodule everyone will have to recursively add parents.
-
carlspring over 5 years@MaximilianSchulz: There is no perfect world, as they say... This is just one option of doing it.