Exception when using Jacoco

plugins

(Max Mustermann) #1

After a gradle init --type java-application I added id 'jacoco' to the plugins section of the build.gradle file, but when running ./gradlew build (using gradle 4.10.2) I get the following error:

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)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
FATAL ERROR in native method: processing of -javaagent failed
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:2000)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
… 9 more

What do I have to do to fix this?


(René Groeschke) #2

Which java version did you use? From a glance it looks like it’s not compatible with the Jacoco version.

cheers,
rené


(Max Mustermann) #3

gradle --v says:

JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)

Thanks, I guess I’ll try a different java version


(Max Mustermann) #4

Does gradle offer the latest Jacoco version (0.8.2)?

https://github.com/jacoco/jacoco/releases states:

Experimental support for Java 11 and Java 12 class files

I tried adding a version number, but I get:

Error resolving plugin [id: ‘jacoco’, version: ‘0.8.2’]
Plugin ‘jacoco’ is a core Gradle plugin, which cannot be specified with a version number.


(René Groeschke) #5

You can configure of the used jacoco version as described in the userguide at https://docs.gradle.org/current/userguide/userguide_single.html#example_configuring_jacoco_plugin_settings


(Max Mustermann) #6

Thanks, this did the trick!