我的项目中有一个第三方依赖项,它使用开放式版本引用来引用其依赖项:
<version>[4.0,)</version>
我如何在我的项目中覆盖这个,以便我的依赖项不使用高于特定版本(例如 6.0)的依赖项版本? (6.0以后的版本需要一些我根本不需要的其他软件包)
最佳答案
如果您在项目中显式指定传递依赖项,则您指定的版本将优先。
例如。在 POM 中添加对 com.foo:bar 的依赖,其版本范围具有独占上限,如下所示:
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>[4.0,6.0)</version>
</dependency>
</dependencies>
更新(2):我刚刚测试了这个,它确实工作(我只是在我的测试项目中出现了拼写错误)。这是我的测试说明。
我有 3 个测试项目:测试基础、测试依赖和测试传递。 测试库项目对测试依赖有直接依赖,测试依赖对测试传递有开放式依赖。 我安装了 3 个版本的 test-transitive:0.0.1、1.0.1 和 2.0.1 如果我在测试库上执行 dependency:tree 我会看到以下内容:
name.seller.rich:test-base:jar:0.0.1
\- name.seller.rich:test-dependency:jar:0.0.1:compile
\- name.seller.rich:test-transitive:jar:2.0.1:compile
如果我在 test-base 中添加对 test-transitive 的显式依赖,并将依赖范围设置为 [0.0.1,2.0.0),我会得到这棵树:
name.seller.rich:test-base:jar:0.0.1
+- name.seller.rich:test-dependency:jar:0.0.1:compile
\- name.seller.rich:test-transitive:jar:1.0.1:compile
关于maven-2 - 如何限制第 3 方包依赖项引用的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1197010/