Gradle fails with Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Could not initialize class org.codehaus.groovy.runtime.InvokerHelperShort 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
What does the error look like?
Could not initialize class org.codehaus.groovy.runtime.InvokerHelperGradle 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.properties2Fix
Raise the wrapper to a Gradle that supports your JDK, and check that your Android Gradle plugin accepts it.
./gradlew :wrapper --gradle-version latest3Verify
Gradle starts and prints its version without the error.
./gradlew --versionConfirmed by docs.gradle.org
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 -version2Fix
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 --versionConfirmed by developer.android.com
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
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile 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