简体   繁体   English

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

[英]How to inherit maven dependencies from parent to another parent?

I have problems with managing inherited dependencies. 我在管理继承的依赖项时遇到问题。 I have , at the top of the level, my "top" level project, with its own pom.xml which has 在顶层,我有“顶层”项目,它有自己的pom.xml,其中包含

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

On the other side, I have my "second level" project which inherits the top project and I want to inherit junit dependency so: 另一方面,我有一个“第二级”项目,该项目继承了顶层项目,并且我想继承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>

But this is catching dependency version. 但这正在捕获依赖版本。 It says "The managed version could not be determinated, the artifact is managed in com.test.second-level-test:0.0.1-SNAPSHOT" 它说:“无法确定托管版本,工件在com.test.second-level-test:0.0.1-SNAPSHOT中进行管理”

Does anybody have any idea about how to fix this? 有人对如何解决这个问题有任何想法吗? Regards 问候

Your 2nd level pom should look like this (dependencies should be directly under project): 您的2级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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM