[英]Why do I get a NoSuchMethodError in my java unit tests but the IDE doesn't show classpath problems?
I have a unit test that uses some methods of the com.google.guava API, that is included as sub-dependencies in some other dependencies I declared in my pom.xml.我有一个单元测试,它使用 com.google.guava API 的一些方法,它作为子依赖项包含在我在 pom.Z0F635D0E0F3874FFF8B581C132E6CA.7 中声明的其他一些依赖项中。 The IDE, in my case eclipse, didn't show any problems.
IDE,在我的例子中是 eclipse,没有显示任何问题。
But when I run the test I get the error:但是当我运行测试时,我得到了错误:
com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
I have seen other users who fixed this problem by excluding guava like this:我见过其他用户通过像这样排除番石榴来解决此问题:
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
but that didn't help.但这没有帮助。 Instead it also caused classpath errors in my non-test code.
相反,它还在我的非测试代码中导致了类路径错误。 What can I do instead?
我能做些什么呢?
I found out that if you explicitly add the dependency for guava in your pom, the error is gone!我发现如果你在你的 pom 中显式地添加对番石榴的依赖,错误就消失了!
So I just added this dependency:所以我只是添加了这个依赖:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
In my case, this error was fixed by using a newer version of activeobjects (2.0.0 --> 3.0.0)就我而言,此错误已通过使用更新版本的 activeobjects (2.0.0 --> 3.0.0) 得到修复
<properties>
<ao.version>3.0.0</ao.version>
</properties>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.