gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:08:00 25 4
gpt4 key购买 nike

我有一个看起来像这样的多模块项目:

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

  • module2 中的 pom.xml 依赖于 module1。

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

    The projects in the reactor contain a cyclic reference.



    这是我在 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 上执行 mvn dependency: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

    在我看来,module1 中没有对 module2 的任何引用。那么循环引用从何而来?

    编辑:这是调试日志:
    + 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] ------------------------------------------------------------------------

    最佳答案

    在这种情况下发生在我身上。

    module_child_X 在 module_root pom.xml 中指定了 2 次:

    - 作为一个模块

    (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>


    - 作为依赖

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


    解决方案?

    删除了 module_child_X 作为依赖项。它已经被指定为一个模块。

    关于Maven 说我在多模块项目中有一个循环引用,但不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11349354/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com