简体   繁体   English

Gradle 错误:无法初始化 class org.codehaus.groovy.runtime.InvokerHelper

[英]Gradle error: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

I need to see my dependencies in Gradle to fix a problem with multiple SLF4J bindings.我需要在 Gradle 中查看我的依赖项,以解决多个 SLF4J 绑定的问题。
However, when I run 'gradle dependencies' I get the error:但是,当我运行“gradle dependencies”时出现错误:

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper无法初始化 class org.codehaus.groovy.runtime.InvokerHelper

In a similar question in stack-overflow Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper在堆栈溢出Android Studio 中的类似问题中无法初始化 class org.codehaus.groovy.runtime.InvokerHelper
it was recommended to建议

  1. install java jdk-14安装 java jdk-14
  2. upgrade to gradle version 6.3升级到 gradle 版本 6.3

I changed the jdk to 14 in IntelliJ in 2 places:我在 IntelliJ 的 2 个地方将 jdk 更改为 14:

  1. File -> Project Structure -> Project -> Project SDK文件 -> 项目结构 -> 项目 -> 项目 SDK
  2. Preferences -> Gradle -> Gradle JVM首选项 -> Gradle -> Gradle JVM

I attempted to update gradle from the command line with: 'gradle wrapper --gradle-version 6.3' and got the same error:我试图从命令行更新 gradle:'gradle wrapper --gradle-version 6.3' 并得到同样的错误:

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper无法初始化 class org.codehaus.groovy.runtime.InvokerHelper

I then changed the field 'distributionUrl' in the file 'gradle-wrapper.properties' to 'gradle-6.3', as instructed here https://github.com/gradle/gradle/issues/10248 .然后,按照https://github.com/gradle/gradle/issues/10248的说明,我将文件“gradle-wrapper.properties”中的字段“distributionUrl”更改为“gradle-6.3”。

I tried various combinations of jdk and gradle versions but nothing seems to work.我尝试了 jdk 和 gradle 版本的各种组合,但似乎没有任何效果。

So from your repo, if you have gradle-wrapper.properties like this:所以从你的仓库中,如果你有这样的 gradle-wrapper.properties:

➜ cat gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

On first compilation, Gradle tells you that:在第一次编译时,Gradle 告诉你:

  build file '/Users/tim/Code/Java/brobotREST/build.gradle': 36:
     all buildscript {} blocks must appear before any plugins {} blocks in the script

So if you move the buildscript section up to the top of the build.gradle file, it all seems to work因此,如果您将buildscript部分移动到 build.gradle 文件的顶部,这一切似乎都有效

And I get:我得到:

➜ ./gradlew -version

------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------

Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          14 (Azul Systems, Inc. 14+36)
OS:           Mac OS X 10.15.4 x86_64

Had a similar problem on Windows 10 caused by a java version issue.由 java 版本问题引起的 Windows 10 上存在类似问题。 In build.gradle set the java source compatibility flag;build.gradle 中设置 java 源兼容性标志; For java 1.8 this is对于java 1.8这是

sourceCompatibility = '1.8'源兼容性 = '1.8'

then check the system version is the same然后检查系统版本是否相同

java -version java-版本

I had a similar problem on macOS.我在 macOS 上遇到了类似的问题。 It seems, it was a problem with version difference by IntelliJ IDEA and Gradle.看来,这是 IntelliJ IDEA 和 Gradle 版本差异的问题。 I adjusted the Gradle version in /gradle/gradle-wrapper.properties.我在 /gradle/gradle-wrapper.properties 中调整了 Gradle 版本。 In my case I have set: distributionUrl=https://services.gradle.org/distribution/gradle-6.6.1-bin.zip就我而言,我设置了:distributionUrl=https://services.gradle.org/distribution/gradle-6.6.1-bin.zip

and now it works.现在它可以工作了。 See also Gradle: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper另请参阅 Gradle:无法初始化 class org.codehaus.groovy.runtime.InvokerHelper

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误无法初始化 class org.codehaus.groovy.runtime.InvokerHelper - Error Could not initialize class org.codehaus.groovy.runtime.InvokerHelper 无法初始化 class org.codehaus.groovy.runtime.InvokerHelper - Could not initialize class org.codehaus.groovy.runtime.InvokerHelper Gradle 从命令行构建失败并出现异常,“无法初始化 class org.codehaus.groovy.runtime.InvokerHelper” - Gradle build from command line fails with an exception, “Could not initialize class org.codehaus.groovy.runtime.InvokerHelper” 使用 Oracle JDK 14 时,所有 gradle (6.2.2) 任务都失败并显示“无法初始化类 org.codehaus.groovy.runtime.InvokerHelper” - When using Oracle JDK 14 all gradle (6.2.2) tasks fail with "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper" "Android Studio 无法初始化类 org.codehaus.groovy.runtime.InvokerHelper" - Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper react-native run-android 不工作。 无法初始化 class org.codehaus.groovy.runtime.InvokerHelper - react-native run-android not working. Could not initialize class org.codehaus.groovy.runtime.InvokerHelper 无法初始化类 org.codehaus.groovy.reflection.ReflectionCache - Could not initialize class org.codehaus.groovy.reflection.ReflectionCache Gradle:找不到org.codehaus.groovy:groovy:1.0.0 - Gradle : Could not find org.codehaus.groovy:groovy:1.0.0 java.lang.NoClassDefFoundError:无法初始化 class org.codehaus.groovy.vmplugin.v7.Java7 - java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 获取 NoClassDefFoundError:无法初始化类 org.codehaus.groovy.vmplugin.v7.Java7 - Getting NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM