简体   繁体   English

Maven说我在多模块项目中有一个循环引用,但不知道为什么

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

I have a multi-module project that looks like this: 我有一个如下所示的多模块项目:

  • module1 模块1
    • pom.xml pom.xml
  • module2 模块2
    • pom.xml pom.xml
  • pom.xml pom.xml

The pom.xml in module2 has a dependency on module1. module2中的pom.xml对module1有依赖性。

When I run mvn clean compile I get the following error: 当我运行mvn clean compile时,出现以下错误:

The projects in the reactor contain a cyclic reference. 反应堆中的项目包含循环引用。

Here are my dependencies in module1: 这是我对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: 即使我在module1上执行mvndependency:tree,我也会得到以下信息:

[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. 在我看来,在module1中没有任何对module2的引用。 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. 问题不在于是否module1和module2相互依赖。 The problem was that module2 is a Maven plugin and in my root pom.xml I had the plugin in the section. 问题在于module2是一个Maven插件,在我的根pom.xml中,该部分中有该插件。 I removed that plugin from the build and it started working. 我从构建中删除了该插件,它开始工作。

It happened to me in this circumstances. 在这种情况下发生在我身上。

The module_child_X was specified 2 times at module_root pom.xml: 在module_root pom.xml中两次指定了module_child_X:

- 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. 删除了module_child_X作为依赖项。 It is already specified as a module. 它已被指定为模块。

I do nearly the same, and I use IDEA. 我几乎做同样的事情,并且我使用IDEA。

I have a project A, which depends on a module B. In the pom file of A, B was declared as a dependency. 我有一个项目A,该项目依赖于模块B。在A的pom文件中,B被声明为依赖项。 This is OK. 还行吧。 In the pom file of B, A was declared as its parent. 在B的pom文件中,A被声明为其父项。 I removed this information, and as it was requested in the error message I added the version number of B in its pom file. 我删除了此信息,并按照错误消息中的要求,在其pom文件中添加了B的版本号。

And now it is OK. 现在可以了。

I had exactly the same issue in a multimodule ear project. 在多模块Ear项目中,我遇到了完全相同的问题。 The ejb pom had a dependency on the web module (compile scope) and the web pom a dependency on the ejb module. ejb pom依赖于web模块(编译范围),而web pom依赖于ejb模块。 As soon as i removed the ejb's pom dependency on the web module, the project build fine. 一旦删除了Web模块上的ejb的pom依赖项,项目就可以正常构建。 It makes sense that the intramodule dependencies must be unidirectional after all, in order to avoid cyclic references. 为了避免循环引用,模块内依赖关系毕竟必须是单向的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何引用多模块Maven项目? - How can I reference a multi-module maven project? 我如何编译一个多模块Maven项目,其中一个模块同时具有clojure和Java代码 - How can I compile a multi-module maven project, where a module have both clojure and java code Maven - 无法在多模块项目中激活配置文件 - Maven - can't activate profiles in multi-module project 如何在没有指定版本的情况下拥有多模块Maven项目? - How can I have a multi-module Maven project without specifying the version all over the place? Maven多模块项目中的循环参考。 我该怎么做才能解决 - Cyclic reference in maven multi module project. What can I do to fix it Quarkus 多模块循环引用问题 - Quarkus multi-module cyclic reference problem Maven:从多模块项目中只构建一个模块 - Maven: Build only one module out of multi-module project Maven多模块项目 - Maven Multi-Module Project 为什么我的多模块 Maven 项目中的某个模块不起作用? - Why a module in my multi-module maven project doesn't work? 在一个多模块的maven项目中,我可以根据另一个模块的DependencyReducedPom做一个模块来计算传递依赖吗? - In a multi-module maven project, can I make a module to calculate transitive dependencies based on the DependencyReducedPom of another module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM