Reputation: 11699
I would like to create a Maven Parent POM file with a groupId of com.company.maven
, which gives its children a default groupId of com.company
. Is this possible? If so, how can I accomplish this?
Upvotes: 2
Views: 4760
Reputation: 13967
In contradiction to the accepted anser it's in fact possible, that the parent POM has a different groupId
than the child POMs. This is a useful feature in Maven that allows building a hierarchical project structure with centrally managed configurations (such as dependencies, plugins, and other common settings) while allowing individual modules or projects to maintain their own groupId
s.
Here's a simple example to illustrate how a parent POM and child POMs can be configured with different groupId
s:
pom.xml
of the parent)<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.parent</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
pom.xml
of a child module)<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.parent</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.example.child</groupId>
<artifactId>child-module</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
groupId
of the parent POM and the child POM can be different, which facilitates the organization of large projects where different teams or subprojects might use different naming conventions or repository structures.dependencyManagement
section.This flexibility in configuration allows Maven to be effectively used in diverse and complex project environments.
Upvotes: 0
Reputation: 97477
Just create the parent pom like:
<project...>
<groupId>com.company.maven</groupId>
<artifactId>parent</artifactId>
<version>..</version>
...
</project>
and define in the child pom:
<project...>
<parent>
<groupId>com.company.maven</groupId>
<artifactId>parent</artifactId>
<version>..</version>
</parent>
<groupId>com.company</groupId>
</project>
In other words it's possible to do so but i wouldn't do it cause i would have named the parent "com.company" whereas the child "com.company.maven". I would compare the groupId with the java package name which represent folders so your idea of setting the groupId doesn't make sense.
Upvotes: 2
Reputation: 114817
Like a java class, that doesn't know "its" subclasses, a parent pom does not know its child poms. So the parent pom will not be able to set or overwrite attributes of it's children.
Upvotes: 0
Reputation: 69389
I don't think this is possible. Also, it flies in the face of the Maven Guide to Naming Conventions, which recommends that (if anything), the child modules should append to the parent groupId, not vice versa.
Upvotes: 0