runningcode / gradle-doctor

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

Provide the IDE restart hint when JAVA_HOME is null #188

Open LouisCAD opened 2 years ago

LouisCAD commented 2 years ago

Hello,

On macOS, if you keep an IntelliJ IDE open and restart the computer, after it's re-open automatically (granted you kept the box check), the shell configuration (~/.zshrc on macOS 11+) will not be taken into account because the IDE is not launched like it was from JetBrains Toolbox or other means.

To illustrate what I'm saying, here's a code snippet that I used to diagnose the issue:

println(System.getenv("SHELL"))
println(System.getenv("PATH"))
println(System.getenv("JAVA_HOME"))

After updating my computer to a newer macOS, after which it reopened my previously open IntelliJ IDEA instance, here's what I got in the console:

/bin/zsh
/usr/bin:/bin:/usr/sbin:/sbin
null

As you can see, both the PATH and the JAVA_HOME environment variables are wrong, but the shell is the correct one.

In this state, Gradle Doctor was (rightfully) complaining with the JAVA_HOME is not set. error.

After trying several unsuccessful fixing steps, including reopening the project and trying to fix the project Gradle JDK, I closed IntelliJ and reopened it, and along with Gradle Doctor no longer showing an error, I got the correct values:

/bin/zsh
/bin/zsh
/Users/me/.nvm/versions/node/v14.18.0/bin:/Users/me/.sdkman/candidates/kotlin/current/bin:/Users/me/.sdkman/candidates/java/current/bin:/Users/me/.sdkman/candidates/gradle/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/me/dev/tools/JB_IDEs_shell_scripts:/Users/me/Library/Android/sdk/tools:/Users/me/Library/Android/sdk/platform-tools
/Users/me/.sdkman/candidates/java/current

I think it'd be great that Gradle Doctor detects when the PATH environement variable is wrong (/usr/bin:/bin:/usr/sbin:/sbin), and simply suggests to restart the IDE, or check that the IDE is launched from the right shell with the right parameters if relevant (maybe on Linux ?).

I personally didn't find out alone that restarting the IDE would be the fix and lost some time on that, and I guess I'm not the only one suffering from that.

BTW, I can submit a PR if you're okay with providing this feature.

All the best!

Louis CAD

runningcode commented 2 years ago

Thanks for reporting this. i've never heard of this happening before.

How often does this happen? When this does happen, does it cause the IDE's Gradle Daemon to be incompatible with the command line version?

LouisCAD commented 2 years ago

It happens each time you reboot while keeping the IDE open before and letting macOS relaunch it. For me, that's not often, but troubleshooting is a pain, I mean, I didn't find the root cause myself, it's a Linux experienced macOS user that could help me. And yes, it causes daemon incompatibilities.

runningcode commented 2 years ago

I think this is quite an edge case. What are the situations where the PATH variable is wrong and how can Gradle Doctor detect that? I just want to be sure we don't have any false positives here.

LouisCAD commented 2 years ago

It's possible that there are other situations leading to this.

If I were to send a PR, I'd reflect that fact in the wording, by making it clear that it's possible that simply restarting the IDE is the fix when the user is on macOS.

JLLeitschuh commented 1 year ago

I'm also getting an error that JAVA_HOME isn't set in IntelliJ. The guide on the site documents how to fix this for Android Studio, but not for IntelliJ Ultimate. It seems the UIs in the screenshots aren't present in IntelliJ.

runningcode commented 1 year ago

Thanks for letting us know. Not having Intellij instructions is a separate issue than the one described in this ticket. Please file separately.