Maven says I have a cyclic reference in multi-module project but can't figure out why

circular dependency maven multi module project
maven multi module version best practices
maven multi module project dependencies between modules
resolve cyclic dependency in maven
maven release multi module project
maven inter module dependencies
maven cyclic dependency detection
which of the following is not a dependency scope in maven

I have a multi-module project that looks like this:

  • module1
    • pom.xml
  • module2
    • pom.xml
  • pom.xml

The pom.xml in module2 has a dependency on module1.

When I run mvn clean compile I get the following error:

The projects in the reactor contain a cyclic reference.

Here are my dependencies in module1:

<dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.48</version>
    </dependency>
</dependencies>

I can't figure out why it says there is a cyclic reference. Even when I do mvn dependency:tree on module1 I get the following:

[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- com.jcraft:jsch:jar:0.1.48:compile
[INFO] \- junit:junit:jar:4.8.2:test

It looks to me like there aren't any references to module2 in module1. So where is the cyclic reference coming from?

Edit: Here is the log with debug on:

+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_31
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.BuildFailureException: The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:295)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: hidden.org.codehaus.plexus.util.dag.CycleDetectedException: Edge between 'Vertex{label='com.myorg:module2'}' and 'Vertex{label='com.myorg:module1'}' introduces to cycle in the graph com.myorg:module1 --> com.myorg:module2 --> com.myorg:module1
at hidden.org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:143)
at hidden.org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:123)
at org.apache.maven.project.ProjectSorter.<init>(ProjectSorter.java:118)
at org.apache.maven.execution.ReactorManager.<init>(ReactorManager.java:99)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:288)
... 11 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Jul 05 17:21:21 EDT 2012    
[INFO] Final Memory: 3M/244M
[INFO] ------------------------------------------------------------------------

Ah! It was a misleading error.

The problem wasn't that there both module1 and module2 depended on each other. The problem was that module2 is a Maven plugin and in my root pom.xml I had the plugin in the section. I removed that plugin from the build and it started working.

[DevOps] Multi-module Maven Projects, When I run mvn clean compile I get the following error: The projects in the reactor contain a cyclic reference. Here are my dependencies in module1:  This post provides a more in-depth view of dependency management and versioning in a multi-module Maven project, looking at common problems and solutions. Dependency Management and Versioning With

It happened to me in this circumstances.

The module_child_X was specified 2 times at module_root pom.xml:

- As a module

(pom.xml of the root module)
<dependency>
    <groupId>module_root</groupId>
    <artifactId>module_child_X</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>jar</type>
</dependency>

- As a dependency

(pom.xml of the root module)
<modules>
    <module>module_child_X</module>
    ...
</modules>

Solution?

Removed the module_child_X as a dependency. It is already specified as a module.

Dependency Management and Versioning With a Maven Multi , “The projects in the reactor contain a cyclic reference.” In order to avoid these cyclic references (which multi-module maven projects strictly do not allow), the best practice is to always extract your common code into a separate module in order to resolve the cyclicity. Customizing child project settings. Fixing eclipse warnings. Dependency management and versions.

I do nearly the same, and I use IDEA.

I have a project A, which depends on a module B. In the pom file of A, B was declared as a dependency. This is OK. In the pom file of B, A was declared as its parent. I removed this information, and as it was requested in the error message I added the version number of B in its pom file.

And now it is OK.

Thanks to mavens behind Apache Maven!, I used NetBeans 8.2, but it can be accomplished with simple mvn commands. POM is basically a container of sub-modules. This is really useful when having dozens or more projects because you know exactly what We might say it is an API for clients. Also, cyclic dependencies are not allowed. Multi Module Maven Project. In this tutorial we will show you how to configure a multi module Maven project with multiple sub modules. By using Maven you can leverage all the goodies it provides like: standardisation, dependency management, common build structure, versioning and many more.

I had exactly the same issue in a multimodule ear project. The ejb pom had a dependency on the web module (compile scope) and the web pom a dependency on the ejb module. As soon as i removed the ejb's pom dependency on the web module, the project build fine. It makes sense that the intramodule dependencies must be unidirectional after all, in order to avoid cyclic references.

Maven multi module best practices, When I started using Apache Maven to build projects, I had no clue on what was Project dependencies, plugins and many more can be configured in POM. Consider a multi-module project with two modules say Module A, Module B. maven errored out as below mentioning about the cyclic reference!! Maven's Multi-module project. A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. Now, the submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

Authoring Multi-Project Builds, This is all OK, but I was dreading synchronizing the Maven projects anymore to Providing guidelines for best practices Say you have a multi-module project to avoid these cyclic references (which multi-module maven projects strictly do not  1.1. Maven parent project. The parent maven project is of packaging type ‘pom’. It makes the project as an aggregator – it won’t produce further artifacts. 1.2. Maven child projects/modules. Maven child projects are independent maven projects but inherit properties from parent project. All child projects inside a parent project can be build with a single command.

Cyclic reference error · Issue #35 · culturecommunication/ginco , Running tasks by their absolute path. As we have seen, you can run a multi-​project build by entering any subproject dir and execute the build from there. All  Multi-Module use of dependency-check-maven is currently unclear I would like the project to clarify multi-module use of the dependency-check-mavenplugin, specifically for access to some of its configuration resources.

Java 9 Modularity Revealed: Project Jigsaw and Scalable Java , [ERROR] The projects in the reactor contain a cyclic reference: Edge to host and review code, manage projects, and build software together. Ok, I have installed Maven 3.1.1. \user123\Documents\WindowsPowerShell\Modules;C:\​Program As a workaround, you can disable tests with -DskipTests  Reference. Maven has many other command line options such as -o, -fae and -rf that can be used to tweak and improve your builds if used wisely. See the Maven command line help for reference, or simply execute Maven with the -h (or --help) option: mvn -h

Comments
  • Can you post relevant log running in debug mode - mvn -X clean compile?
  • I just updated the post to include the log
  • The dependency in the parent module when removed introduces issues in all the other modules where the removed dependency in the root module is specified.