Maven循环依赖 [英] Maven cyclic dependency

查看:88
本文介绍了Maven循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的maven项目有多个maven模块.这些模块中的两个(产品和功能)相互依赖.当我将模块作为依赖项包含在pom文件中时,一个!标记出现在模块上.在运行maven安装时,出现此错误.

my maven project has multiple maven modules. Two of those modules (product and feature) are dependent on each other. When I include the modules as dependencies in the pom files, an ! mark appears on the modules. On running maven install I get this error.

The projects in the reactor contain a cyclic reference: Edge between 
'Vertex{label='com.catalog:feature:0.0.1-SNAPSHOT'}' and 
'Vertex{label='com.catalog:product:0.0.1-SNAPSHOT'}' introduces to 
cycle in the graph com.catalog:product:0.0.1-SNAPSHOT --> 
com.catalog:feature:0.0.1-SNAPSHOT --> com.catalog:product:0.0.1-
SNAPSHOT @

不添加依赖项,产品将无法访问功能模块中定义的功能,反之亦然.

Without adding the dependencies Product can't access functions defined in Feature module and vice versa.

父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.catalog</groupId>
    <artifactId>catalog</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.enterprise</artifactId>
            <version>4.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.4.1.Final</version>
        </dependency>

        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency> 

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.6</version>
        </dependency>

   </dependencies>

   <modules>
       <module>category</module>
       <module>resource</module>
       <module>hibernate</module>
       <module>product</module>
       <module>helper</module>
       <module>feature</module>
   </modules>

产品模块pom.xml

Product module 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.catalog</groupId>
        <artifactId>catalog</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>product</artifactId>

    <name>product</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>hibernate</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>category</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>helper</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>feature</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

功能模块pom.xml

Feature module 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.catalog</groupId>
        <artifactId>catalog</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <groupId>com.catalog</groupId>
    <artifactId>feature</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>feature</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>hibernate</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.catalog</groupId>
            <artifactId>product</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

推荐答案

设计气味.

重构您的模块.基本上,两个模块中所需的所有内容都应成为一个公共依赖项.您的依赖树中不能有循环,否则将无法正常工作.

Refactor your modules. Basically everything which is needed in both modules should go into a common dependency. You cannot have cycles in your dependency tree, it just won't work.

这篇关于Maven循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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