title: How to get rid of "Could not initialize plugin: interface org.mockito.plugins.MockMaker" when launching JUnit with Mockito using OpenJDK 12
body: <p>I've been migrating a project from Java 8 to Java 12. Everything went well except for unit tests. When I compile and launch tests with Maven, many tests fail with the following message:</p>
  
  <pre><code>java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
      at com.tetratech.csoft.ui.jfx.AppContextTest.&lt;init&gt;(AppContextTest.java:22)
  Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@35fd987b
  Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
  
  Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
  
  Java               : 12
  JVM vendor name    : Oracle Corporation
  JVM vendor version : 12+33
  JVM name           : OpenJDK 64-Bit Server VM
  JVM version        : 12+33
  JVM info           : mixed mode, sharing
  OS name            : Windows 10
  OS version         : 10.0
  
  Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
  </code></pre>
  
  <p>When lauched from IntelliJ, I get a more detailed message:</p>
  
  <pre><code>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)
      at com.sun.proxy.$Proxy7.isTypeMockable(Unknown Source)
      at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
      at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
      at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:240)
      at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:228)
      at org.mockito.internal.MockitoCore.mock(MockitoCore.java:61)
      at org.mockito.Mockito.mock(Mockito.java:1907)
      at org.mockito.Mockito.mock(Mockito.java:1816)
      at com.tetratech.csoft.ui.jfx.AppContextTest.&lt;init&gt;(AppContextTest.java:22)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
      at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
      at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@460d0a57
      at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:54)
      at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
      at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
      at org.mockito.internal.configuration.plugins.PluginRegistry.&lt;init&gt;(PluginRegistry.java:22)
      at org.mockito.internal.configuration.plugins.Plugins.&lt;clinit&gt;(Plugins.java:19)
      at org.mockito.internal.util.MockUtil.&lt;clinit&gt;(MockUtil.java:24)
      ... 29 more
  Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
  Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
  
  Java               : 12
  JVM vendor name    : Oracle Corporation
  JVM vendor version : 12+33
  JVM name           : OpenJDK 64-Bit Server VM
  JVM version        : 12+33
  JVM info           : mixed mode, sharing
  OS name            : Windows 10
  OS version         : 10.0
  </code></pre>
  
  <p>To solve this, as suggested as answers to similar problems, I modified <code>pom.xml</code> to include the following dependancies:</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
              &lt;version&gt;2.25.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-junit-jupiter&lt;/artifactId&gt;
              &lt;version&gt;2.25.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.bytebuddy&lt;/groupId&gt;
              &lt;artifactId&gt;byte-buddy&lt;/artifactId&gt;
              &lt;version&gt;1.9.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.bytebuddy&lt;/groupId&gt;
              &lt;artifactId&gt;byte-buddy-agent&lt;/artifactId&gt;
              &lt;version&gt;1.9.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.objenesis&lt;/groupId&gt;
              &lt;artifactId&gt;objenesis&lt;/artifactId&gt;
              &lt;version&gt;3.0.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>According to some people, this is the kind of problem that occurs when launching tests with a JRE instead of a JDK. Since I'm using OpenJDK 12, this is not the case.</p>
  
  <p>Tests failing in OpenJDK 12 used to run successfully in Java 8. There were no modifications other than the ones I've shown you. <code>org.mockito.plugins.MockMaker</code> is required in our tests because many classes come from legacy code, with a lot of final classes. And as you can see in the message log, tests are launched with OpenJDK 12 running on Windows 10.</p>
  
  <p>Is there any way to run these tests with <code>Mockito</code>? I know that <code>PowerMockito</code> can probably solve this problem, but using it means a lot of modifications in test classes.</p>
  
  <p>Thanks.</p>