3

升级到 Java 16 后,我无法使 ktlint gradle 插件工作。它在扔

Execution failed for task ':runKtlintCheckOverMainSourceSet'.
A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
   java.lang.ExceptionInInitializerError (no error message)

Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task     ':runKtlintCheckOverMainSourceSet'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$3(ExecuteActionsTaskExecuter.java:186)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:268)

Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:336)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:142)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:94)
    ...
Caused by: java.lang.ExceptionInInitializerError
        at org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel.<clinit>(LanguageLevel.java:25)
        at org.jetbrains.kotlin.com.intellij.core.CoreLanguageLevelProjectExtension.<init>(CoreLanguageLevelProjectExtension.java:26)
        at org.jetbrains.kotlin.com.intellij.core.JavaCoreProjectEnvironment.<init>(JavaCoreProjectEnvironment.java:42)
        ...
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module @58f87189
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.makeAccessible(ReflectionUtil.java:252)
        at org.jetbrains.kotlin.com.intellij.util.ReflectionUtil.getDeclaredMethod(ReflectionUtil.java:269)
        at org.jetbrains.kotlin.com.intellij.DynamicBundle.<clinit>(DynamicBundle.java:22)
        ... 32 more

我知道这是由更严格的模块检查(JEP 396)引起的,但我无法为插件设置 JVM 参数。我试过了:

  • 设置环境变量JAVA_OPTS=--illegal-access=warn
  • 设置org.gradle.jvmargs=--illegal-access=warn -Dkotlin.daemon.jvm.options=--illegal-access=warn_gradle.properties

但是这两种尝试都没有帮助,我没有想法。

4

2 回答 2

0

Gradle 6.x 似乎不支持 Java 16,Gradle 7 将支持 Java 16。

于 2021-04-07T18:14:54.163 回答
0

您可以根据迁移指南更新 Gradle 插件以获取最新版本:

gradle wrapper --gradle-version 7.0

那应该可以解决此错误消息。否则,您也可以更改文件中的版本gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip

我还将 kotlin 插件更新为kotlin("jvm")最新版本1.4.32

于 2021-04-11T20:55:46.027 回答