如何从父级继承maven依赖关系到另一个父级?

时间:2014-09-22 13:15:41

标签: java maven parent-child

我在管理继承的依赖项时遇到问题。在这个关卡的顶层,我有" top" level项目,有自己的pom.xml,有

<dependencyManagement>
        <dependencies>
            <!-- Utils -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
            </dependency>
        </dependencies>
</dependencyManagement>

另一方面,我有我的第二级&#34;继承顶级项目的项目,我想继承junit依赖项,所以:

    <parent>
        <artifactId>com.test</artifactId>
        <groupId>top-level-class</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

<dependencyManagement>
        <dependencies>
            <!-- Utils -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </dependency>
        </dependencies>
</dependencyManagement>

但这是捕获依赖版本。它说&#34;托管版本无法确定,工件在com.test.second-level-test中管理:0.0.1-SNAPSHOT&#34;

有没有人知道如何解决这个问题?此致

1 个答案:

答案 0 :(得分:4)

你的第二级pom应该是这样的(依赖项应该直接在项目中):

        <project blabla>
    <parent>
        <artifactId>com.test</artifactId>
        <groupId>top-level-class</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

     ....

        <dependencies>
            <!-- Utils -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </dependency>
        </dependencies>
     ...

  </project>
相关问题