Maven 2 - 测试和编译中的不同依赖版本 [英] Maven 2 - different dependency versions in test and compile
问题描述
我的项目依赖于commons-httpclient [2.0](编译)。
I have project that depends on commons-httpclient [2.0] (compile).
我想写一些jbehave测试 - jbehave-core 3.4.5(测试)。
这两个依赖项都依赖于commons-lang但在不同的版本中 - 1.0.1和2.5。
I would like to write some jbehave tests - jbehave-core 3.4.5 (test). Both this dependencies depend on commons-lang but in different versions - 1.0.1 and 2.5.
当我执行 mvn package 时,我在测试中得到[BUID FAILURE]部分。
在surefire-plugin输出中我的测试用例有一个例外:
When I execute mvn package I get [BUID FAILURE] in tests section. There is an exception for my testcase in surefire-plugin output:
java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.substringBeforeLast(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
当我查看源代码时 - 在commons-lang 1.0.1中 - 确实没有StringUtils .substringBeforeLast(...)方法。
为什么maven在commons-httpclient(编译)中使用commons-lang而在测试中不使用jbehave-core?
As I looked in source code - in commons-lang 1.0.1 - indeed, there is no StringUtils.substringBeforeLast(...) method. Why maven uses commons-lang from commons-httpclient (compile) and not from jbehave-core in testing?
我不能排除这种冲突commons-httpclient中的依赖,所以它必须保持编译时间。
I can't afford to exclude this conflicting dependency in commons-httpclient so it must stay in compile time.
那么如何解决这个问题呢? - 测试中的commons-lang 2.5版本和编译时的1.0.1。
So how can this be resolved? - commons-lang 2.5 version in testing and 1.0.1 in compile time.
推荐答案
尝试定义2个不同的< dependency>
具有不同版本和范围的标签。使用标记< scope> test< / scope>
测试内部依赖项和< scope> compile< / scope>
用于编译。
try to define 2 different <dependency>
tags with different versions and scopes. Use tag <scope>test</scope>
inside dependency for tests and <scope>compile</scope>
for compilation.
这篇关于Maven 2 - 测试和编译中的不同依赖版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!