Atif
Atif

Reputation: 129

Maven Cyclic reference when root pom has plugin which is common to two or more child modules

So i have a project with the structure as follows-:

pom.xml
\
 ---Module A (Child)
 ---Module B (Maven child  plugin with Dependency on A)
 ---Module C (Child Dependency on A)
 ---Plugin B

the parent pom looks like the following

<modules>
<module>A</module>
<module>B</module>
<module>C</module>
</modules>

<plugins>
<plugin>
  B
</plugin>
</plugins>

POM for A has no dependencies and has just the parent-: parent

POM for B has

<parent>parent</parent>
<dependencies>
      <dependency>A</dependency>
</dependencies>

POM for C also has

<parent>parent</parent>
<dependencies>
      <dependency>A</dependency>
</dependencies>

With the above,maven gives me the following error-:

org.apache.maven.ProjectCycleException: The projects in the reactor contain a cyclic reference:

Edge between 'B' and 'A' introduces to cycle in the graph A->parent->B->A

What am i doing wrong and how should i structure the project?I want to keep everything in one place.

Upvotes: 0

Views: 2255

Answers (1)

Darth Android
Darth Android

Reputation: 3502

You should move your plugin declaration inside of the parent into the pluginManagement tag so that you can set the version (but not actually use it), and then in individual projects that need the plugin, simply name the plugin in your plugins tag.

Additionally, A cannot use plugin B if B depends upon A. Sorry, can't be done; You'll need to find a way to make one do without the other. Additionally I don't think B can use itself as a plugin, since that has to resolve before it can even begin to build B. C and any other modules (D, E, etc.) can use B though.

Upvotes: 1

Related Questions