java.lang.IllegalStateException: Could not initialize plugin: MockMaker

Do not explicitly include mockito, let powermock pull in what it needs.


Worked:

dependencies { 
def mockito_version = '2.7.1' // For local unit tests on your development machine
 testCompile "org.mockito:mockito-core:$mockito_version" // For instrumentation tests on Android devices and emulators
 androidTestCompile "org.mockito:mockito-android:$mockito_version"
 }

No need to comment initiMocks


I got this problem resolved after adding transitive dependencies for 'mockito-core'. I was facing this problem in eclipse. I was using 'mockito-core 3.8.0' along with 'mockito-junit-jupiter 3.8.0'. At first I tried to resolve this by changing JRE to JDK in Project/ Java Build Path ((as many have posted this as resolution), but that did not solve the problem. Then I added below 3 transitive dependencies for 'mockito-core 3.8.0' explicitly, and it worked!

1. net.bytebuddy » byte-buddy  v1.10.20
2. net.bytebuddy » byte-buddy-agent  v1.10.20
3. org.objenesis » objenesis  v3.1

(https://mvnrepository.com/artifact/org.mockito/mockito-core/3.8.0 - see compiled dependencies)


In my case, I was working on a project that does not use the maven build system. So this is what worked for me.

Navigated to the maven repo for mockito (used v2.26): https://mvnrepository.com/artifact/org.mockito/mockito-core/2.26.0. I downloaded the jar. On the same page at the bottom, I looked up the dependencies. For mockito 2.26.0, these dependencies are:

  • Byte Buddy v.1.9.10 (https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy/1.9.10)
  • Byte Buddy Java Agent v1.9.10 (https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy-agent/1.9.10)
  • Objenesis v2.6 (https://mvnrepository.com/artifact/org.objenesis/objenesis/2.6) I downloaded the jar files for the above mockito dependencies.

In Eclipse I created a user library containing the four jar file and added it to my project.

NB: (creating the library is optional, you can add the jars directly to your project build path)

Hope this helps someone.