在maven项目的构建路径中检测到一个循环

时间:2017-05-15 06:43:19

标签: java maven

此错误有很多头条新闻。但我无法为我找到解决方案。

我打算创建一个多模块项目。 parentProjectprojectAprojectDprojectUtilprojectWprojectW的包装 war ,包含projectAprojectDprojectUtil jar 文件。< / p>

projectParent
├───projectA
│   ├───src
│   │   └───main/java/projectA
│   │       ├───ClassA.java
│   │       └───ClassB.java
│   └───pom.xml ---- packaging = jar & dependencies = projectD and projectUtil
├───projectD
│   ├───src
│   │   └───main/java/projectD
│   │       ├───ClassC.java
│   │       └───ClassD.java
│   └───pom.xml ---- packaging = jar & dependencies = projectA and projectUtil
├───projectUtil
│   ├───src
│   │   └───main/java/projectUtil
│   │       └───StringUtil.java
│   └───pom.xml ---- packaging = jar & dependencies = no dependency
├───projectW
│   ├───src
│   │   └───main/java/projectW
│   │       └───Test.java
│   └───pom.xml ---- packaging = war & dependencies = projectA, projectD and projectUtil
└───pom.xml ---- packaging = pom & modules = projectA, project D, projectUtil and projectW

在项目的构建路径中发现了一个错误,例如已经检测到一个循环。我把错误变成了像互联网上的解决方案一样的警告。

  

Windows - &gt;偏好 - &gt; Java的&GT;编译器 - &gt;建筑 - &gt;圆   依赖

Test.java已成功运行,但由于此警告,maven无法安装。有没有人建议我解决方案有以下例外?

enter image description here

Test.java

ClassA a = new ClassA();
a.getD().mrbDunya();

ClassD d = new ClassD();
d.getB().sayHello();

修改

parentProject / pom.xml的

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.earslan</groupId>
    <artifactId>projectParent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Project Parent</name>

    <modules>
        <module>projectA</module>
        <module>projectD</module>
        <module>projectUtil</module>
        <module>projectW</module>
    </modules>

</project>

了projectA / pom.xml的

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.earslan</groupId>
        <artifactId>projectParent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>projectA</artifactId>
    <packaging>jar</packaging>

    <name>Project A</name>

    <dependencies>
        <dependency>
            <groupId>com.earslan</groupId>
            <artifactId>projectD</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.earslan</groupId>
            <artifactId>projectUtil</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

projectUtil / pom.xml的

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.earslan</groupId>
        <artifactId>projectParent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>projectUtil</artifactId>
    <packaging>jar</packaging>

    <name>Project Util</name>

    <dependencies>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

projectW / pom.xml的

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.earslan</groupId>
        <artifactId>projectParent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>projectW</artifactId>
    <packaging>war</packaging>

    <name>Project W</name>

    <dependencies>
        <!-- Project Files Dependency -->
        <dependency>
            <groupId>com.earslan</groupId>
            <artifactId>projectA</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.earslan</groupId>
            <artifactId>projectD</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.earslan</groupId>
            <artifactId>projectUtil</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!-- JSF Dependency -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>

        <!-- PrimeFaces Dependency -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.1</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>bootstrap</artifactId>
            <version>1.0.10</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

1 个答案:

答案 0 :(得分:1)

  

├──projectA
  │├───src
  ││└───main/ java / projectA
  ││├───ClassA.java
  ││└───ClassB.java
  │└───pom.xml---- packaging = jar&amp; dependencies = projectD和projectUtil
  ├───projectD
  │├───src
  ││└───main/ java / projectD
  ││├───ClassC.java
  ││└───ClassD.java
  │└───pom.xml---- packaging = jar&amp; dependencies = projectA和projectUtil

项目A取决于项目D,项目D取决于项目A,该项目显然是圆形的。

您需要通过

进行重构
  1. 在项目之间移动课程;
  2. 将两者合并在一起;
  3. 引入第三个项目(A和D都依赖于它),只包含相互依赖的类。