I have a gradle project and when my build.gradle dependencies section looks like this:
dependencies { implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19' testImplementation 'junit:junit:4.12' // testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4' compileOnly 'org.projectlombok:lombok:1.18.4' apt 'org.projectlombok:lombok:1.18.4' }
it leads to this exception:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18) at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
to fix this issue, I've substituted "mockito-all" with "mockito-core".
dependencies { implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' // testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19' testImplementation 'junit:junit:4.12' testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4' compileOnly 'org.projectlombok:lombok:1.18.4' apt 'org.projectlombok:lombok:1.18.4' }
The explanation between mockito-all and mockito-core can be found here: https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/
mockito-all.jar besides Mockito itself contains also (as of 1.9.5) two dependencies: Hamcrest and Objenesis (let’s omit repackaged ASM and CGLIB for a moment). The reason was to have everything what is needed inside an one JAR to just put it on a classpath. It can look strange, but please remember than Mockito development started in times when pure Ant (without dependency management) was the most popular build system for Java projects and the all external JARs required by a project (i.e. our project’s dependencies and their dependencies) had to be downloaded manually and specified in a build script.
On the other hand mockito-core.jar is just Mockito classes (also with repackaged ASM and CGLIB). When using it with Maven or Gradle required dependencies (Hamcrest and Objenesis) are managed by those tools (downloaded automatically and put on a test classpath). It allows to override used versions (for example if our projects uses never, but backward compatible version), but what is more important those dependencies are not hidden inside mockito-all.jar what allows to detected possible version incompatibility with dependency analyze tools. This is much better solution when dependency managed tool is used in a project.