Gradle ignores JAVA_HOME in Android Studio and uses bundled JBR instead

I’m facing an issue where Gradle does not use JAVA_HOME and instead falls back to Android Studio’s bundled JDK (JBR).

Environment

  • Gradle: 9.4.1

  • Kotlin: 2.3.0

  • macOS (Apple Silicon)

  • Android Studio

Configuration

In .idea/gradle.xml:

<option name="gradleJvm" value="#JAVA_HOME" />

My JAVA_HOME:

/Library/Java/JavaVirtualMachines/amazon-corretto-21.jdk/Contents/Home/bin

Problem

Gradle Doctor reports:

Gradle is not using JAVA_HOME
JAVA_HOME is /Library/.../amazon-corretto-21.jdk/.../bin
Gradle is using /Applications/Android Studio.app/.../jbr/.../bin

However, running ./gradlew -version in terminal shows:

Launcher JVM: 21.0.9 (Amazon Corretto)

Questions

  1. Why does Android Studio ignore #JAVA_HOME?

  2. Why is it using bundled JBR instead?

  3. Is this expected behavior?

  4. What is the correct way to make Gradle use JAVA_HOME consistently?

Any help would be appreciated.

What do you mean with “Gradle uses”.
There can be various different JDKs used for example for the daemon, for workers, for various forked processes, …
Do you use JVM toolchains?
Do you use daemon criteria file?
Which JVM is it you are concerned about?

Why do you think it is a Gradle topic?
Gradle does not by itself “look at JAVA_HOME or use the IDE JDK instead”.
The IDE controls which JDK is used if you do not use things like JVM toolchains or daemon criteria files.

When Gradle might look at JAVA_HOME is, when you use the Gradle CLI to start Gradle,
or also when discovering JDKs for usage as JVM toolchains.