Reputation: 649
I have problem with multi module maven project when I need to specify sub-module dependencies with parent module
Here is my configuration for pom.xml
Parent POM:
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>childA</module>
<module>childB</module>
</modules>
childA POM
<parent>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>childA</artifactId>
<dependencies>
<dependency>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
ChildB POM
<parent>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>childB</artifactId>
I was able to build childB when running mvn clean install
inside childB.
I am getting an error when build Parent and ChildA with error message
ERROR] Failed to execute goal on project parent: Could not resolve dependencies for project com.parent:childA:jar:1.0-SNAPSHOT: Could not find artifact com.parent:parent:jar:1.0-SNAPSHOT -> [Help 1]
I need added dependency inside childA pom.xml to parent package due to some classes available on parent package
How i should resolve this issue?
Upvotes: 2
Views: 403
Reputation: 131326
The childA
pom makes no sense.
It has the same artifact as both dependency parent and build dependency :
<parent>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
and :
<dependencies>
<dependency>
<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
First : the dependency resolution will never success as it is a chicken and egg problem.
The parent module that produces a pom will be available only as the reactor build is terminated but it will be terminated only as all modules, among childA
, would terminate their build.
Second : Multi module maven project and parent module are designed to be packaged as pom
and not as a jar
.
Which interest to declare it as a dependency of childA
?
Just remove it and keep it as parent of childA
.
I need added dependency inside childA pom.xml to parent package due to some classes available on parent package
You don't need to specify it as a dependency to achieve it.
Child projects inherit many things from parent project, among dependencies.
Upvotes: 1