Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven inheritance and aggregation

I'm just curious, what happens if there are used both inheritance and aggregation in the same maven application? This is the application structure:

my-project-app

  • my-project-jar
  • my-project-war

Now, in app's pom.xml, I declare jar and war projects as modules, and in the same time the the poms from both modules declare the app pom as their parent. It is create some kind of redundancy here, isn't it?

What is the best solution for this case?

like image 821
grozandrei Avatar asked Mar 07 '26 07:03

grozandrei


1 Answers

It's not redundant. They both do different things.

If you use aggregation (define <modules>), you just say which projects have to be built, and its package type is pom.

If you inherit (define <parent>), you'll inherit the parent pom's preferences.

See:

Inheritance and aggregation create a nice dynamic to control builds through a single, high-level POM. You will often see projects that are both parents and aggregators. For example, the entire maven core runs through a single base POM org.apache.maven:maven, so building the Maven project can be executed by a single command: mvn compile. However, although both POM projects, an aggregator project and a parent project are not one and the same and should not be confused. A POM project may be inherited from - but does not necessarily have - any modules that it aggregates. Conversely, a POM project may aggregate projects that do not inherit from it.

More infos here.

like image 165
xoned Avatar answered Mar 09 '26 19:03

xoned



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!