我正在尝试运行此处提供的 kotlin 代码的测试:https://github.com/ligi/ipfs-api-kotlin 使用 gradlew
我收到下面列出的错误。 有人可以告诉我这个错误意味着什么吗?
> Task :test FAILED
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at line: 422
我的 build.gradle 中缺少以下内容:
jacoco {
toolVersion = "0.8.6"
}
虽然很明显,build.gradle 可以从其他 gradle 文件继承属性,但由于我无法弄清楚的原因,
jacoco
传递到一个子项目,但没有传递到另一个子项目。
确保您使用的是 JDK-11, 如果使用maven,请确保;
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
确保您使用的是最新的 jacoco。
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
当我将 jdk1.8 升级到 openjdk11 时,我遇到了类似的问题,但通过更新 toolVersion =“0.8.6”(在 jdk1.8 中使用 toolVersion =“0.8.1”)解决了这个问题
该问题来自 Java 版本,该版本不需要太新。
sdk 安装 java 19.3.0.2.r8-grl
一切顺利。
按照以下步骤操作后,它对我来说效果很好。
在 Eclipse 中,转到 Window--Preferences--java。右键单击已安装的 JRE。添加已安装的 JDK 路径并删除其他路径。
就我而言,我的机器中有 java 11 和 17,并且我的
JAVA_HOME
指向 java 17,尽管我在我的 gradle 中指定了 java 11,如下所示:
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
和
jacoco {
toolVersion = "0.8.2"
}
我仍然面临同样的问题,所以我更新了我的
JAVA_HOME
以将其指向我的java SDK 11的位置,然后它就可以正常工作了。