user1589188
user1589188

Reputation: 5736

Is parent pom created under the same groupid of its children or under its own/parent?

Hi I want to know the practice on creating a parent pom. So

1.Parent pom

<groupId>my.code</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>

then child

<parent>
    <groupId>my.code</groupId>
    <artifactId>project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>my.code.project</groupId>
<artifactId>child-A</artifactId>

or

2.Parent pom

<groupId>my.code.project</groupId>
<artifactId>project-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>

then child

<parent>
    <groupId>my.code.project</groupId>
    <artifactId>project-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>child-A</artifactId>

Any reason behind one or the other? Or just a personal taste? Thank you

Upvotes: 3

Views: 2346

Answers (2)

khmarbaise
khmarbaise

Reputation: 97487

Usually if you have only a single level of folder structure like this:

 +-- root (pom.xml)
      +--- mod1 (pom.xml)
      +--- mod2 (pom.xml)
      +--- mod3 (pom.xml)

I would suggest to use only the same groupId like com.company.project. But if you a multi level structure like this:

 +-- root (pom.xml)
      +--- mod1 (pom.xml)
      !      +-- mod11 (pom.xml)
      !      +-- mod12 (pom.xml)
      +--- mod2 (pom.xml)
      !      +-- mod21 (pom.xml)
      !      +-- mod22 (pom.xml)
      +--- mod3 (pom.xml)

The root groupId i would suggest com.company.project. Than i would use different groupId in mod1 like com.company.project.part1 etc. and in mod2 com.company.project.part3 etc.

Upvotes: 4

Chris Gerken
Chris Gerken

Reputation: 16392

Either one would work, although I use the groupId to refer to the company or organization owning the artifact. Since the company owning the parent artifact usually owns the child artifact, I'd expect to see the same groupId between parent and child poms. For that reason I would use the second structure.

Upvotes: 4

Related Questions