I'm new to Maven, and I'm trying to understand why my company's modules are organized into 'module groups', but also each sub-module declares its parent explicitly. I don't quite understand what the POM Reference is trying to say about the difference between inheritance and aggregation.
For example, a parent module:
<groupId>example.group</groupId>
<artifactId>util</artifactId>
<packaging>pom</packaging>
<name>Util Parent</name>
<modules>
<module>util_client</module>
<module>util_core</module>
<module>util_server</module>
</modules>
And one of its children:
<parent>
<artifactId>util</artifactId>
<groupId>example.group</groupId>
<version>trunk-SNAPSHOT</version>
</parent>
<groupId>example.group.util</groupId>
<artifactId>util_core</artifactId>
<packaging>jar</packaging>
<name>Util Core</name>
Why declare it both ways? Is it redundant? To make things even more confusing, some of the util submodules depend upon eachother:
<groupId>example.group.util</groupId>
<artifactId>util_client</artifactId>
<packaging>jar</packaging>
<name>Util Client</name>
<dependencies>
<dependency>
<groupId>example.group.util</groupId>
<artifactId>util_core</artifactId>
</dependency>
</dependencies>
Sorry if this is a doozy of a question, but wow this is confusing! Thanks for your help.
In Maven, project aggregation is similar to project inheritance, except that the change is made in the parent pom instead of the child pom. Maven uses the term module to define a child or subproject, which is part of a larger project. An aggregate project can build all the modules together.
What is Maven Dependency? In Maven, a dependency is just another archive—JAR, ZIP, and so on—which our current project needs in order to compile, build, test, and/or run. These project dependencies are collectively specified in the pom. xml file, inside of a <dependencies> tag.
groupId – a unique base name of the company or group that created the project. artifactId – a unique name of the project. version – a version of the project. packaging – a packaging method (e.g. WAR/JAR/ZIP)
When you define sub-modules, you can build and release them all at once from the top level.
When you use inheritance in the second example, you can use definitions from the parent POM defined once, (Like which versions of software to use)
In the last example, when one module needs resources from another module, you can add it as a dependency and it will download and include it in the build path automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With