runningcode / gradle-doctor

The right prescription for your Gradle build.
http://runningcode.github.io/gradle-doctor
Apache License 2.0
722 stars 46 forks source link

Android Studio overrides original global JAVA_HOME env value #343

Open iamironz opened 2 months ago

iamironz commented 2 months ago

Hey! Thank you for this plugin, very much appreciate the effort you put into development.

I have the following setup for my project:

The plugin version is 0.9.2.

Settings used:

doctor {
    downloadSpeedWarningThreshold = .5f
    GCWarningThreshold = 0.10f
    GCFailThreshold = 0.9f
    daggerThreshold = 5000
    failOnEmptyDirectories = true
    allowBuildingAllAndroidAppsSimultaneously = true
    warnWhenJetifierEnabled = true
    negativeAvoidanceThreshold = 500
    warnWhenNotUsingParallelGC = true
    disallowCleanTaskDependencies = true
    warnIfKotlinCompileDaemonFallback = true
    appleRosettaTranslationCheckMode = com.osacky.doctor.AppleRosettaTranslationCheckMode.ERROR
    javaHome {
        ensureJavaHomeMatches = true
        ensureJavaHomeIsSet = true
        failOnError = false
    }
}

However, a while ago, Google introduced something bizarre: they started overriding the global JAVA_HOME to their bundled JDK, and moved out the originally defined value to the GRADLE_LOCAL_JAVA_HOME.

As per newer versions of Android Studio we have:

Screenshot 2024-04-18 at 11 23 03 AM

Where GRADLE_LOCAL_JAVA_HOME is my actual JAVA_HOME. As you can see, they forcibly swapped it, which is extremely weird IMO.

If I switch to GRADLE_LOCAL_JAVA_HOME in AS I will obviously get following the message after the configuration is complete:

=============================== Gradle Doctor Prescriptions ============================================
| JAVA_HOME is not set.                                                                                |
| Please set JAVA_HOME so that switching between Android Studio and the terminal does not trigger a fu |
| ll rebuild.                                                                                          |
| To set JAVA_HOME: (using bash)                                                                       |
| echo "export JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.bash_profile                                 |
| or `~/.zshrc` if using zsh.                                                                          |
|                                                                                                      |
========================================================================================================
| Gradle is not using JAVA_HOME.                                                                       |
| JAVA_HOME is null                                                                                    |
| Gradle is using /opt/homebrew/Cellar/openjdk@17/17.0.10/libexec/openjdk.jdk/Contents/Home            |
| This can slow down your build significantly when switching from Android Studio to the terminal.      |
| To fix: Project Structure -> JDK Location.                                                           |
| Set this to your JAVA_HOME.                                                                          |
|                                                                                                      |
========================================================================================================

And this is expected, the doctor plugin works just fine here. But now within the AS, there's no option to use my real JAVA_HOME and doctor plugin option with its checking at the same time anymore.

Probably you have some suggestions/thoughts about this?

Thank you!

dsvoronin commented 1 week ago

Just to add more context. I had some questions regarding this new GRADLE_LOCAL_JAVA_HOME and how to properly use it: https://issuetracker.google.com/issues/214428183#comment9 , see Googler's answer