【发布时间】:2020-08-22 09:00:23
【问题描述】:
假设B:1.0.1 具有传递依赖关系A:1.0.1,但子项目应该依赖于A:1.0.2(有意覆盖传递依赖关系)。
很容易发现<dependencyManagement> 中的依赖顺序会影响版本覆盖,因此在B:1.0.1 之前的子pom 中添加A:1.0.2 将强制使用A:1.0.2,即使作为B:1.0.1 的依赖。
在这种情况下,我正在寻找一种在父 pom 中声明 A:1.0.2 并从其所有子代中删除样板的方法。不幸的是,以下设置导致在最终工件中使用这两个版本:A:1.0.1(作为 B:1.0.1 的依赖项出现)和 A:1.0.2(来自父 pom 中的显式声明)。
如何在所有子项目中强制使用版本A:1.0.2,将声明保留在父项目中?
父 pom:
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>g</groupId>
<artifactId>A</artifactId>
<version>1.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
儿童 pom:
<parent>
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>my-child</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>g</groupId>
<artifactId>A</artifactId>
<!-- version 1.0.2 comes from the parent pom -->
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>g</groupId>
<artifactId>B</artifactId>
<version>1.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
【问题讨论】:
标签: maven pom.xml dependency-management transitive-dependency