Apache Maven: What is the difference between inheritance, aggregation, and dependencies?

I am new to Maven, and I’m trying to understand why my company’s modules are organized into “module groups”, but also each submodule explicitly declares its parent. I do not quite understand what the POM Reference is trying to say about the difference between inheritance and aggregation .

For example, the 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 his 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 announce it in both directions? Is this redundant? To make things even more confusing, some of the usage submodules depend on 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 an unnecessary question, but wow this is confusing! Thank you for your help.

+6
source share
1 answer

When you define submodules, you can create 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 (for example, which software versions to use)

In the last example, when one module needs resources from another module, you can add it as a dependency, and it will automatically load and include it in the build path.

+9
source

Source: https://habr.com/ru/post/897762/


All Articles