Maaz Zindani

Loading the index…

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

Gradle fails on Windows with 'Unable to get mutable Windows environment variable map'

ErrorUnable to get mutable Windows environment variable map

Short 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.

  • Applies to Gradle 7.3 to 9.x, JDK 17, JDK 21, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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%
  2. 2Match what you see, then jump to its fix

    1. 1gradlew.bat --version shows a Gradle older than the minimum for the JVM lineThe Gradle version is too old for the JDKFix
    2. 2JAVA_HOME points at one JDK, the IDE or the daemon uses anotherGradle runs on a different JDK than the one you thinkFix

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.properties

2Fix

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.3

3Verify

The version output shows the new Gradle, and a build starts.

gradlew.bat --version
gradlew.bat build

Confirmed by docs.gradle.org

Did this fix it?

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 --version

2Fix

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 --stop

3Verify

Open a new terminal (setx does not change the current one) and check again.

echo %JAVA_HOME%
gradlew.bat --version

Confirmed by docs.gradle.org

Did this fix it?

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

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

Next step

Want this handled for good?

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