JDK16 和 Mac OS 上的 Mockito - 无法初始化插件

时间:2023-05-03
本文介绍了JDK16 和 Mac OS 上的 Mockito - 无法初始化插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@4158debd
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 

Could not initialize inline Byte Buddy mock maker.

    
It appears as if your JDK does not supply a working agent attachment mechanism.
    Java               : 16
    JVM vendor name    : Oracle Corporation
    JVM vendor version : 16.0.2+7-67
    JVM name           : Java HotSpot(TM) 64-Bit Server VM
    JVM version        : 16.0.2+7-67
    JVM info           : mixed mode, sharing
    OS name            : Mac OS X
    OS version         : 11.5
    
    Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process

在使用 Mockito 3.7.7 的 Maven 3.8.1 和 JDK16.02 上出现上述错误,在全新的设置中,无法弄清楚原因.我已经尝试了从 3.7 到 3.11 的每个 Mockito 版本,但无济于事.

Getting the above error on Maven 3.8.1 and JDK16.02 with Mockito 3.7.7, on a fresh setup and cannot figure out why. I have tried every Mockito version from 3.7 all the way to 3.11 to no avail.

但是,这些配置适用于 Windows 10 Pro 上基于 JDK15 的旧设置.

These configurations however works on an older setup based on JDK15 on Windows 10 Pro.

推荐答案

  • Mockito 核心依赖于一个名为 byte-buddy 的库,这个问题主要发生在 mockito 找不到匹配的 byte buddy jar 版本时.

    • Mockito core depends on a library called byte-buddy and this problem is mostly occurred when mockito doesn’t find a matching byte buddy jar version.

      找出您的项目正在使用的 mockito 核心版本.在 Eclipse 中,您可以通过导航到右键单击项目->属性->Java 构建路径 ->库标签

      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

      • 在 maven 存储库中搜索该版本的 mockito 核心.

      • Search maven repository for that version of mockito core.

      查看编译依赖部分.记下 byte-buddy 的正确依赖版本并包含在项目中.如果 jar 已包含在其他版本中,请使用此正确版本覆盖该版本.

      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.

      构建应用程序并再次运行测试.您与 MockMaker 相关的问题现在必须解决.

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

      这篇关于JDK16 和 Mac OS 上的 Mockito - 无法初始化插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:Mockito 模拟对象突然抛出 NPE 下一篇:Mockito 可以捕获多次调用的方法的参数吗?

相关文章