Issue
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?
Solution
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 in 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.
Answered By - xoned
Answer Checked By - Senaida (JavaFixing Volunteer)