Konubinix' opinionated web of thoughts

Difference Between Maven Inheritance (Parent) and Maven Aggregation (Module)

Fleeting

difference between maven parent and maven module.

The documentation sometimes is ambiguous, saying that an aggregating maven project is a parent, while it generally refers to parent in the context of maven project inheritance.

If you have several Maven projects, and they all have similar configurations, you can refactor your projects by pulling out those similar configurations and making a parent project. Thus, all you have to do is to let your Maven projects inherit that parent project, and those configurations would then be applied to all of them.

https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#project-inheritance-vs-project-aggregation

And if you have a group of projects that are built or processed together, you can create a parent project and have that parent project declare those projects as its modules. By doing so, you’d only have to build the parent and the rest will follow.

https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#project-inheritance-vs-project-aggregation

  • maven parent conveys the meaning of having a POM with more generic information that other POM would want to include,
  • maven module conveys the meaning of having a global POM that include other POMs so that they all get built together.

But of course, you can have both Project Inheritance and Project Aggregation. Meaning, you can have your modules specify a parent project, and at the same time, have that parent project specify those Maven projects as its modules. You’d just have to apply all three rules:

  • Specify in every child POM who their parent POM is.
  • Change the parent POMs packaging to the value “pom” .
  • Specify in the parent POM the directories of its modules (children POMs)

https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#project-inheritance-vs-project-aggregation

If a maven project is a parent or an aggregator, it cannot produce jar, as you are forced to make it a pom project.