0

在https://github.com/gradle/gradle/issues/15038中似乎提到了这个问题,但是从该线程中不清楚如何解决它,所以在这里发布。我正在运行 Java 15:

> java --version
openjdk 15.0.2 2021-01-19

和 Gradle 6.6.1:

> gradle --version

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          14.0.1 (Oracle Corporation 14.0.1+14)
OS:           Mac OS X 10.16 x86_64

我已经开始了一个测试项目,选择Application它的类型,并添加了jacoco插件:

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Apply the application plugin to add support for building a CLI application.
    id 'application'

    id 'jacoco'
}

但是,如果我尝试./gradlew test我得到以下错误:

> ./gradlew test

> Task :test
java.lang.instrument.IllegalClassFormatException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:94)
        at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
        at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
        at java.base/java.lang.ClassLoader.defineClass2(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:784)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:705)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:586)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:634)
        at java.base/java.lang.Class.forName(Class.java:546)
        at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:854)
        at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1078)
        at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1301)
        at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1386)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:188)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:287)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:258)
        at java.base/java.util.Calendar.createCalendar(Calendar.java:1693)
        at java.base/java.util.Calendar.getInstance(Calendar.java:1661)
        at java.base/java.text.SimpleDateFormat.initializeCalendar(SimpleDateFormat.java:677)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:621)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:600)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.getLastResortErrorLogFile(SystemApplicationClassLoaderWorker.java:162)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:111)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.io.IOException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:109)
        at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:92)
        ... 37 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 59
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:195)
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:176)
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:162)
        at org.jacoco.agent.rt.internal_43f5073.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:280)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:75)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:107)
        ... 38 more

BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed

前面提到的 GitHub 问题页面似乎说可以通过指定项目扩展名(https://docs.gradle.org/6.7/userguide/jacoco_plugin.html#sec:configuring_the_jacoco_plugintoolVersion )来解决这个错误,但目前还不清楚我要选择哪个工具版本;我试过了jacoco

jacoco {
    toolVersion "0.8.5"
}

但具有相同的错误结果。知道如何解决此错误吗?

4

1 回答 1

1

搜索“jacoco java 15”时,第一个结果就是更新日志。

快照构建 0.8.7.202101150304 (2021/01/15) ...

  • JaCoCo 现在正式支持 Java 15

JaCoCo 0.8.6 列出了对 Java 15 的实验性支持。

于 2021-02-02T21:30:59.600 回答