问题
I installed JDK 14 and started using it. However projects that use Gradle 6.2.2 cannot work, the following error "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper" appear each time I try to invoke a Gradle Task. Other projects , for instance maven projects and plain java projects work OK.
An easy way to reproduce this error is by creating a new folder and attempting to run the init task. For instance:
gradle init --type basic
FAILURE: Build failed with an exception.
What went wrong: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 878ms
The PC this example runs windows 10. The java version is:
java --version
java 14 2020-03-17 Java(TM) SE Runtime Environment (build 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
Is there any solution to this problem so that I can make Gradle 6.2.2 work with Oracle JDK 14?
回答1:
As pointed out in the comments above and in Gradle 6.2.2. Compatibility a Java version between 8 and 13 is required to execute Gradle 6.2.2. Java 14 and later versions are not yet supported by Gradle 6.2.2.
Updated answer since Gradle 6.3 release:
Gradle 6.3, supports JDK 14 According to the Gradle 6.3 Release notes .
The following solutions apply:
To keep using Gradle 6.2.2:
- Install a compatible JDK Version (8-13)
Modify gradle.properties to use this version. For example if JDK 13 is installed in: C:/Program Files/Java/jdk-13.0.2 Make sure the following line is in
gradle.properties
.org.gradle.java.home=C:/Program Files/Java/jdk-13.0.2
To Keep using JDK14.
- Install and use Gradle 6.3 (or higher)
After setting up your system, verify that you are running the correct versions. For instance when using Java 14 and Gradle 6.3 you will get something like:
Type C:\>gradle --version
following to get the gradle version:
C:>gradle --version
Gradle 6.3
Build time: 2020-03-24 19:52:07 UTC Revision:
bacd40b727b0130eeac8855ae3f9fd9a0b207c60Kotlin: 1.3.70 Groovy: 2.5.10 Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019 JVM: 14 (Oracle Corporation 14+36-1461) OS: Windows 10 10.0 amd64
Type java --version
to get the java version:
C:>java --version java 14 2020-03-17 Java(TM) SE Runtime Environment (build 14+36-1461) Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
If you use Gradle wrapper you can use the following command to change the gradle wrapper to version 6.3:
gradle wrapper --gradle-version=6.3
来源:https://stackoverflow.com/questions/60742006/when-using-oracle-jdk-14-all-gradle-6-2-2-tasks-fail-with-could-not-initializ