Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 603
user1589188 Avatar asked Dec 17 '25 13:12

user1589188


2 Answers

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.

like image 73
Chris Gerken Avatar answered Dec 20 '25 03:12

Chris Gerken


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.

like image 23
khmarbaise Avatar answered Dec 20 '25 01:12

khmarbaise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!