【问题标题】:java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings() - Gradle links same class twice for Mockito jarjava.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings() - Gradle 为 Mockito jar 链接同一类两次
【发布时间】:2020-01-20 08:37:34
【问题描述】:

我在 build.gradle 文件中配置了以下依赖项。

testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.mockito:mockito-all:1.10.19"

并且在运行测试时得到以下错误堆栈跟踪。

java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings()Lorg/mockito/mock/MockCreationSettings;
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:107)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:81)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:69)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:56)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)

我已经尝试调试它。在 IntelliJ 链接的 jar 文件中发现了一些奇怪的东西。 Mockito jar 中的大多数类几乎都显示了两次。

刷新 gradle 依赖项或清除缓存都不起作用。

【问题讨论】:

    标签: spring-boot gradle intellij-idea


    【解决方案1】:

    经过这么多天,我发现问题出在 mockito jar 版本不匹配。 将版本从 mockito-all 更改为 mockito-core build.gradle 到

        testCompile "org.mockito:mockito-core:2.24.0"
        testCompile ("org.springframework.boot:spring-boot-starter-test") {
            exclude group: "org.mockito", module: "mockito-all"
        }
    

    解决了我的问题。

    谢谢

    【讨论】:

      猜你喜欢
      • 2020-05-20
      • 1970-01-01
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 2014-07-08
      相关资源
      最近更新 更多