Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle fails with Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

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

Short answer

This usually means Gradle is running on a JDK newer than that Gradle version supports. Check which Java Gradle uses, then compare it with Gradle's compatibility table: Java 17 needs Gradle 7.3, Java 21 needs 8.5, Java 24 needs 8.14, Java 25 needs 9.1. Upgrade the wrapper or switch the JDK.

  • Applies to Gradle 7.x to 9.x, JDK 17, 21 and 25, Android Studio 2026
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Gradle for its own version and the JVM it runs on. Compare the two numbers with the table in the first cause.

    ./gradlew --version
  2. 2Match what you see, then jump to its fix

    1. 1The first line of ./gradlew --version shows an old Gradle and a new JVM, for example Gradle 7.x on Java 21The wrapper's Gradle version is older than the JDKFix
    2. 2Sync works in Android Studio but ./gradlew in a terminal fails, or the other way roundTerminal and IDE use different JDKsFix

What does the error look like?

  • Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
  • Gradle fails before any task runs, on ./gradlew --version or on sync

Cause 1 of 2

The wrapper's Gradle version is older than the JDK

1Check

Gradle's compatibility table lists the first Gradle that runs on each Java: Java 11 from 5.0, Java 17 from 7.3, Java 21 from 8.5, Java 24 from 8.14, Java 25 from 9.1.0.

grep distributionUrl gradle/wrapper/gradle-wrapper.properties

2Fix

Raise the wrapper to a Gradle that supports your JDK, and check that your Android Gradle plugin accepts it.

./gradlew :wrapper --gradle-version latest

3Verify

Gradle starts and prints its version without the error.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 2

Terminal and IDE use different JDKs

1Check

Gradle started from IDE buttons uses the JDK in the IDE's settings, while a terminal uses JAVA_HOME, or java on PATH if it is unset.

echo $JAVA_HOME
java -version

2Fix

Set JAVA_HOME and the IDE's Gradle JDK to the same JDK, one your Gradle version supports.

export JAVA_HOME=/path/to/jdk-17
export PATH="$JAVA_HOME/bin:$PATH"

3Verify

Run the same Gradle command from both places.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Upgrade the Gradle wrapper before moving to a new JDK, not after.
  • Write down the JDK the project expects and set it in both the IDE and JAVA_HOME.
  • Run ./gradlew --version in CI so the JVM is in the log.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.