Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Oracle JDK 14 all gradle (6.2.2) tasks fail with "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper"

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?

like image 658
Spyros K Avatar asked Mar 18 '20 14:03

Spyros K


People also ask

Can I use Gradle with JDK 14?

Show activity on this post. 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 : Other projects, for instance maven projects and plain java projects work OK with Java 14.

How to solve build failed with an exception in Java 14?

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. FAILURE: Build failed with an exception. Try: Run with --stacktrace option to get the stack trace.

What is the Java JDK?

The JDK is a development environment for building applications using the Java programming language. The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java TM platform.

Which projects are compatible with Java 14?

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.


1 Answers

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

like image 87
Spyros K Avatar answered Oct 22 '22 13:10

Spyros K