Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
build.gradle: use JaCoCo 0.8.1
Browse files Browse the repository at this point in the history
With JDK 10, `./gradlew allTest` fails to run tests, instead spewing out
the following errors on the console:

    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:564)
            at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:510)
    FATAL ERROR in native method: processing of -javaagent failed
            at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:522)
    Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
            at org.jacoco.agent.rt.internal_290345e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:139)
            at org.jacoco.agent.rt.internal_290345e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:100)
            at org.jacoco.agent.rt.internal_290345e.PreMain.createRuntime(PreMain.java:55)
            at org.jacoco.agent.rt.internal_290345e.PreMain.premain(PreMain.java:47)
            ... 6 more
    Caused by: java.lang.NoSuchFieldException: $jacocoAccess
            at java.base/java.lang.Class.getField(Class.java:1958)
            at org.jacoco.agent.rt.internal_290345e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:137)
            ... 9 more

... and so forth

According to a PR[1] on the JaCoCo's issue tracker, this occurs because
"Classes of JDK 10 EA b35 use a new classfile version number and so
JaCoCo Agent 0.7.9 as well as agent from current build of master branch
fail to start". This has been fixed as of JaCoCo 0.8.1, which also
happens to be the latest release.

We do not explicitly specify the version JaCoCo to use in our
build.gradle file, and so the `jacoco` gradle plugin just uses its
default, which happens to be 0.8.0[2] on Gradle 4.6 (the version we are
using). This version of JaCoCo still has this bug, and so we get these
errors.

Fix this by explicitly telling the gradle jacoco plugin to use JaCoCo
version 0.8.1.

[1] jacoco/jacoco#629
[2] gradle/gradle@8a09484
  • Loading branch information
pyokagan committed May 7, 2018
1 parent 8d2322b commit 685e45f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ checkstyle {
toolVersion = '8.1'
}

jacoco {
toolVersion = '0.8.1'
}

jacocoTestReport {
reports {
xml.enabled false
Expand Down

0 comments on commit 685e45f

Please sign in to comment.