OpenJDK11 and JaCoCo
sebasira opened this issue · comments
I'm using JaCoCo and with the latest update I'm getting:
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)
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 src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
Apparently, as expose in this other repo: Jacoco and JDK11 don't play nice
And it seems the solution is:
Specifically upgrading to this version of JDK11:
java version "11-ea" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11-ea+19)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+19, mixed mode)
I had something similar and got it to work properly with this in my Gradle file:
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
Alternatively you could stick to the 29
tag of the Docker image, that still uses OpenJDK 8.
Thanks! I'll try that and let you know! I was using a previous version in the meanwhile
@jangrewe where should I put this?
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
I've try placing it in my app level build.gradle
outside all the inner blocks with no luck.
Ans instead of shooting in the dark I think you can point me out where. And yes, as temporary fix I'm sticking to tag 29.
Also, FWIW I'm using grade wrapper version 5.4.1-all
. Maybe those lines are compatible with newer version and not mine.
Thanks!
I'm using Gradle 6.1.1
Make sure you also use a recent/maintained version of the jacoco plugin!
build.gradle
:
buildscript {
dependencies {
classpath 'com.hiya:jacoco-android:0.2'
}
}
app/build.gradle
:
apply plugin: 'com.hiya.jacoco-android'
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
Thank you now it's working!!
It was due to the fact I had and older version of JaCoCo (v0.8.1) I update it to v0.8.6 and it was perfectly fine!
Reading the changelog, v0.8.2 was the first one in support Java 11
Thanks again! I'm closing this issue