如何限制第三方软件包依赖项引用的版本?

时间:2009-07-28 22:03:24

标签: maven-2

我的项目中有第三方依赖项,它使用开放式版本引用来引用它的依赖项:

<version>[4.0,)</version>

我如何覆盖项目中的 ,以便我的依赖项不会比特定版本6.0更晚使用其依赖项的版本? (6.0以后的版本需要一些我根本不需要的其他软件包)

1 个答案:

答案 0 :(得分:3)

如果在项目中明确指定传递依赖项,则指定的版本优先。

例如。在您的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 如果我做依赖:测试基础上的树我看到了:

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