0

I've read many questions and answers here on SO, but I can't find an aswer that clears my doubts.

I have a big Java project managed with Maven (let's call it MainProj), and it has many dependencies, some of which are other standalone projects done by me and my team.

What I've done is a single maven project for each related project, installed each one into my repository, and imported into the MainProj with standard <dependency></dependency> imports.

I've now discovered inheritance and aggregation in Maven, but what I can't figure out is:

  • Is my MyProject suitable for this structure, or is the standard dependency import the best practice?

  • I've read the concept of superPom (or parent pom), but I can't figure how it works: should I create a standalone pom, not related to any java code, that only manages the childs and other related poms? Or that superPom should be, in my example, the one included in MainProj ?

  • In case, should I import my related projects with inheritance or with aggregation?

Thanks

Leviand
  • 2,745
  • 4
  • 29
  • 43
  • Maybe read the contents on the [maven](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) site. PS. you can have project inheritance and aggregation together. – J_D Aug 28 '18 at 09:02

1 Answers1

1

You can approach this issue in two ways.

1) ParentPOM (SuperPOM)

2) Multi Module Maven Project

Super POM

Super POM (Parent POM) is used to structure the project to avoid redundancies or duplicate configurations using inheritance between pom files. You have a create a separate project for parent POM and all the common dependencies and plugins should be added. Then in the child project, you have to add the parent POM identifier

<parent>
    <groupId>com.parent.demo</groupId>
    <artifactId>MavenExamples</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

Eg: https://howtodoinjava.com/maven/maven-parent-child-pom-example/

Multi Module Project

When multiple modules are parts of a project, the preferred approach is to structure them as a maven multi-module project and delegate the build responsibility completely to Maven. It's doesn't require a new project like Super POM. In the multi-module project, you add all the related project to the Main project. The main project POM acts as a top-level POM (same like Super POM) and contains all the common dependencies and plugins.

Eg: http://www.codetab.org/apache-maven-tutorial/maven-multi-module-project/

Ref: How to structure a multi-modules Maven project to compile it at once?

Vimal David
  • 555
  • 2
  • 7
  • 20