[Solved] IllegalStateException: Could not initialize plugin MockMaker

If you are working on Spring boot applications that automatically include Mockito Core dependency and are facing this error, then you may try the suggested solution.

  • The root cause of this error is the version mismatch between Mockito and ByteBuddy.
  • For a few people, it turned out to be JDK configuration. Make sure the IDE is NOT pointing to a JRE. It should be a JDK path.

1. Problem

Mockito core depends on a library called byte-buddy, and this problem mostly occurs when mockito doesn’t find a matching byte-buddy jar version. The error looks like this:

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
  at org.mockito.internal.configuration.plugins. PluginLoader$1.invoke(PluginLoader.java:74) ~[mockito-core-2.23.4.jar:na]
  at com.sun.proxy.$Proxy61.getHandler(Unknown Source) ~[na:na]
  at org.mockito.internal.util. MockUtil.isMock(MockUtil.java:81) ~[mockito-core-2.23.4.jar:na]
Caused by: java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/loading/ ClassInjector$UsingReflection
  at org.mockito.internal.creation.bytebuddy. SubclassInjectionLoader.<init>(SubclassInjectionLoader.java:28) ~[mockito-core-2.23.4.jar:na]
  at org.mockito.internal.creation.bytebuddy. SubclassByteBuddyMockMaker.<init>(SubclassByteBuddyMockMaker.java:33) ~[mockito-core-2.23.4.jar:na]
  at org.mockito.internal.creation.bytebuddy. ByteBuddyMockMaker.<init>(ByteBuddyMockMaker.java:21) ~[mockito-core-2.23.4.jar:na]
  ... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.bytebuddy.dynamic. loading.ClassInjector$UsingReflection
  at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_171]
  at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171]
  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171]
  at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_171]
  ... 42 common frames omitted

2. Solution

Find out the mockito core version your project is using. In Eclipse, you can check in the project build path by navigating to:

Right click on project -> Properties -> Java build path -> Libraries tab

Mockito core dependency
Mockito core dependency

Search the maven repository for that version of mockito core. To me, it was: https://mvnrepository.com/artifact/org.mockito/mockito-core/2.23.4

Look at the Compile Dependencies section. Note down the correct dependent version of byte-buddy and include in the project. If the jar is already included with some other version, override the version with this correct version.

Correct jar version
Correct jar version

Build the application and run the tests again. Your issue related to MockMaker must be solved by now.

Happy Learning !!


Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.