9

I installed JDK 14 and started using it.

However projects that use Gradle 6.2.2 cannot work, and the following error appears each time I try to invoke a Gradle Task :

Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

Other projects, for instance maven projects and plain java projects work OK with Java 14.

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 that runs this example uses 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?

Spyros K
  • 2,480
  • 1
  • 20
  • 37

1 Answers1

20

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:

    1. Install a compatible JDK Version (8-13)
    2. 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.

    1. 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:
bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin: 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

Spyros K
  • 2,480
  • 1
  • 20
  • 37
  • 1
    Thanks to @ Aniket Sahrawat and @Eenvinvible for the answer in the comments. This answer is provided for completeness and is using the information provided by them. (If you answer I will delete this answer and accept your answer as correct) – Spyros K Mar 18 '20 at 15:10
  • 3
    It seems that the 6.3 release candidate supports JDK 14: https://docs.gradle.org/6.3-rc-2/release-notes.html – Jorn Vernee Mar 18 '20 at 16:03
  • Thanks @Jorn Vernee , I will update this information to the answer. – Spyros K Mar 19 '20 at 08:37
  • 1
    Thanks. Very late last night couldn't work why 'Gradle' wouldn't run after upgraded MacOS: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/ – NOTiFY Mar 25 '20 at 08:00
  • 1
    I'm using both JDK14 and Gradle 6.3, but I'm still getting this error when building from command line. It builds through Android Studio. – Christopher Chalfant Apr 08 '20 at 20:31
  • Check that you are using the correct versions, see the updated answer with information on how to check the gradle and java versions that are available in the path. If you updated the gradle version then you might need to type a specific command. – Spyros K Apr 09 '20 at 07:05
  • 2
    @ChristopherChalfant, try set location for gradle issue discussed here https://github.com/gradle/gradle/issues/10248. Both distributionUrl need to match after upgrading gradle location1: /Users/ChristopherChalfant/Pject/ShoppingList/android/gradle/wrapper/gradle-wrapper.properties location2: /Users/ChristopherChalfant/gradle/wrapper/gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip – nywooz Apr 15 '20 at 11:12
  • 2
    Just a helpful note: Using Windows, I downloaded Gradle 6.3, put it in the same folder as my Gradle 6.0, and set my environment variable Gradle_Home. At this point I expected it to work, but it did not. The information I missed was that I had to make a PATH entry. – Jack J Apr 22 '20 at 10:24