Gradle fails on Windows with 'Unable to get mutable Windows environment variable map'
Unable to get mutable Windows environment variable mapShort answer
This error appears when the Gradle you run is older than the Java it runs on. Gradle only supports a Java version from a given release on: Java 17 needs Gradle 7.3, Java 21 needs 8.5. Upgrade the wrapper, or run the build on a JDK your Gradle version supports.
Fix it fast
1Find out which cause you have
Print the Gradle version and the Java it runs on. They must be a supported pair.
gradlew.bat --version echo %JAVA_HOME%2Match what you see, then jump to its fix
What does the error look like?
Unable to get mutable Windows environment variable map
Cause 1 of 2
The Gradle version is too old for the JDK
1Check
Gradle's compatibility table lists the first Gradle that can run on each Java version: Java 17 needs 7.3, Java 21 needs 8.5, Java 24 needs 8.14 and Java 25 needs 9.1.0.
gradlew.bat --version
type gradle\wrapper\gradle-wrapper.properties2Fix
Raise the wrapper to a Gradle that supports your JDK. Run the task a second time so the wrapper jar and scripts update too.
gradlew.bat :wrapper --gradle-version 8.14.3
gradlew.bat :wrapper --gradle-version 8.14.33Verify
The version output shows the new Gradle, and a build starts.
gradlew.bat --version
gradlew.bat buildConfirmed by docs.gradle.org
Cause 2 of 2
Gradle runs on a different JDK than the one you think
1Check
Gradle's daemon documentation says a mismatch between the Gradle JDK and JAVA_HOME can spawn extra daemons, and tells you to line up the Java versions across environment, toolchains and IDE.
echo %JAVA_HOME%
java -version
gradlew.bat --version2Fix
Point JAVA_HOME and the IDE's Gradle JDK setting at the same JDK that your Gradle version supports, then stop the old daemons.
setx JAVA_HOME "C:\Program Files\Java\jdk-21"
gradlew.bat --stop3Verify
Open a new terminal (setx does not change the current one) and check again.
echo %JAVA_HOME%
gradlew.bat --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Raise the wrapper version in the same commit that raises the JDK.
- Keep one JDK path in JAVA_HOME and in the IDE's Gradle JDK setting.
- Check the Gradle compatibility table before you install a new JDK.
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
Gradle fails because it does not support the Java version you run
Could not determine java version from '21.0.1'.
Gradle can only run on JDK versions it knows.
3 causes, each with a fixMobile apps
Gradle ignores JAVA_HOME and starts a different JDK
Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Gradle does not read JAVA_HOME first.
3 causes, each with a fixMobile 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 fix