135

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

Mr.Eddart
  • 10,050
  • 13
  • 49
  • 77

2 Answers2

228

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

From mvn -h:

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

Sled
  • 18,541
  • 27
  • 119
  • 168
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
41

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.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 1
    I struggled with this issue for hours, and found that some projects are doing this way, such as apache sling, JackRabbit and Artifactory. – accuya Sep 24 '12 at 07:51
  • It isolated maven module inheritance (dependencies, properties etc) from batch building (child modules). – Danubian Sailor Jun 04 '13 at 11:23
  • 4
    Is this considered a best practice? Any blogs or other on this approach? – Sled Jul 16 '13 at 16:25
  • 1
    @ArtB Have you stumbled upon such an article in the meantime? – Tomislav Nakic-Alfirevic Aug 13 '14 at 14:51
  • I have got malformed project warnings when I do this. Maven seem to discourage it. – pdem May 09 '18 at 09:44
  • I 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. – Captain Man Sep 21 '18 at 15:26
  • In 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. – Maximilian Schulz Nov 09 '18 at 13:59
  • 5
    @MaximilianSchulz: There is no perfect world, as they say... This is just one option of doing it. – carlspring Nov 09 '18 at 23:48