我的pom中有两个依赖项,分别称为A和B。A和B都对 Artifact C(cassandra-all)具有传递性依赖项。 A和B使用C的不同版本。依赖关系A是 Artifact Astyanax。
我想保留B附带的C的版本。我通过在A(Astyanax)中为C添加一个排除项来实现。
不幸的是,我希望B的范围是“测试”。这意味着在排除A的情况下,C不会包含在测试范围之外。
我该如何解决?排除项只能用于特定范围吗?另外,我可以指定用于传递依赖项的版本吗?
示例:
这是我的pom的样子:
Artifact A(astyanax),不依赖 Artifact C(称为cassandra-all)
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax</artifactId>
<version>1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
<version>1.1.1.1</version>
<scope>test</scope>
</dependency>
如此具体地讲:当我在测试范围之外运行代码并且仍然仅保留cassandraunit测试范围时,如何包含cassandra-all?
最佳答案
如果我的问题不够清楚,我深表歉意。我解决这个问题的方法一点也不难:
我在这里具体添加:
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>1.1.5</version>
</dependency>
以及以下在运行时缺少的依赖项。
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
关于maven - 如何仅排除特定范围的依赖关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13572502/