Maven说我在多模块项目中有一个循环引用,但不知道为什么 [英] Maven says I have a cyclic reference in multi-module project but can't figure out why

查看:189
本文介绍了Maven说我在多模块项目中有一个循环引用,但不知道为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的多模块项目:

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

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

      module2中的pom.xml对module1有依赖性.

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

      当我运行mvn clean compile时,出现以下错误:

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

      反应堆中的项目包含循环引用.

      The projects in the reactor contain a cyclic reference.

      这是我在module1中的依赖项:

      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>
      

      我不知道为什么它说有一个循环引用.即使当我在module1上执行mvndependency:tree时,我也会得到以下信息:

      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
      

      在我看来,在module1中没有任何对module2的引用.那么循环引用来自哪里?

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

      这是调试打开的日志:

      + 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.

      问题不是模块1和模块2相互依赖.问题在于module2是一个Maven插件,在我的根pom.xml中,该部分中有该插件.我从构建中删除了该插件,它开始工作.

      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.

      这篇关于Maven说我在多模块项目中有一个循环引用,但不知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆