【问题标题】:How to inherit maven dependencies from parent to another parent?如何将 Maven 依赖项从父级继承到另一个父级?
【发布时间】:2014-09-22 13:15:40
【问题描述】:

我在管理继承的依赖项时遇到问题。我有,在级别的顶部,我的“顶级”级别项目,它有自己的 pom.xml,它有

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

另一方面,我有我的“二级”项目,它继承了顶级项目,我想继承 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>

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

有人知道如何解决这个问题吗?问候

【问题讨论】:

  • 只需将其从孩子的 pom 中删除...
  • 您是否将“二级”项目声明为父模块?
  • 我把它命名为 因为我希望这些依赖可以继承到另一个 suns 项目。
  • 是的,我已经将二级项目声明为父模块
  • 我从二级类中删除了依赖项,我直接在子级内部实现了它并且它起作用了。谢谢大家!

标签: java maven parent-child


【解决方案1】:

您的第二级 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>

【讨论】:

  • 但是这样一来这个项目的suns就不会继承junit依赖了吧?
猜你喜欢
  • 2017-08-04
  • 2012-12-02
  • 1970-01-01
  • 2014-01-19
  • 1970-01-01
  • 1970-01-01
  • 2014-04-12
  • 2015-06-09
  • 1970-01-01
相关资源
最近更新 更多