HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Mockito / [Solved] IllegalStateException: Could not initialize plugin MockMaker

[Solved] IllegalStateException: Could not initialize plugin MockMaker

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

1. Problem

Mockito core depends on a library called byte-buddy and this problem is mostly occurred when mocito doesn’t find a matching byte buddy jar version. 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]
	
	...
	...
	[spring-test-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	... 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 project build path by navigating to

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

    Mockito core dependency
    Mockito core dependency
  • Search 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 !!

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. ramiro

    February 19, 2020

    in my case I had to change the JRE libray to JDK
    check Properties/Java Build Path/Libraries

  2. Manuel

    November 27, 2019

    In my case it was an even weirder problem. Somehow, don’t really know why, the directory where IntelliJ was looking for the JDK got changed somewhere along the way. Result was that, overnight, all tests stopped working while throwing this exact same error.
    After struggling with it for a day I finally came up with the solution which was going to File->Project Structure->SDKs, there I chose the JDK the project was set to (Java 11 in my case), and found out it was pointing to a whole different place, I just redirected it to the folder where my JDK was and everything went back to normal.
    Hope it helps!

    • Lokesh Gupta

      November 27, 2019

      Thanks for sharing.

Comments are closed on this article!

Search Tutorials

Mockito Tutorial

  • Mockito – Introduction
  • Mockito – Annotations
  • Mockito – @Mock vs @InjectMocks
  • Mockito – Multiple method calls
  • Mockito – Spring Boot
  • Mockito – MockMaker Error

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)