1

When creating a maven multi-module project, is there any advantage in having a root pom and a separate parent module containing another pom.

For example: Option A:

sample-project

  • sample-module-a
    • pom.xml
  • sample-module-b
    • pom.xml
  • sample-parent
    • pom.xml
  • pom.xml

Option B:

sample-project

  • sample-module-a
    • pom.xml
  • sample-module-b
    • pom.xml
  • pom.xml

In option b, there is no separate parent module, the root pom.xml provides all the parent features.

In option a, there is a root pom and also a pom in parent module and the features are divided between 2 poms.

I just want to understand if there is any advantages of one over other and when would one choose one over the other.

l a s
  • 3,836
  • 10
  • 42
  • 61
  • *It depends*. I've always been working with a single parent pom to define versions and serve as the base (packaging: pom), and a "boot" module as the artifact root (packaging: jar). That way, there is no code at the parent pom. But it's just my experience – Iván Sep 09 '21 at 16:25
  • 1
    I would suggest to have the parent pom in the root location and not in a sub directory because that represents more logical structure of the project. So I would strongly recommend Option B. – khmarbaise Sep 09 '21 at 17:10
  • 1
    In my experience, Option A shown here works better. I've answered a similar question [before](https://stackoverflow.com/a/21590120/944849). – user944849 Sep 09 '21 at 18:09
  • @user944849 What does it mean: Works better? In which way? What does not work in other structure? – khmarbaise Sep 10 '21 at 07:01
  • @khmarbaise - I linked my other answer to explain in detail. To sum - if the parent POM is also the aggregator (as in option B) aggregation happens too soon in the build process which leads to missing or inaccurate results (for anything requiring aggregation, usually reports, code coverage, etc.) – user944849 Sep 10 '21 at 12:39

0 Answers0