I am having a lot of trouble for what should be an easy task. I'm trying to build a simple Java project (just Hello World) with Gradle for one of my courses before classes begin. I cloned the repository, downloaded all the relevant software, and tried gradle build
on the command line. I get the error Supplied javaHome must be a valid directory. You supplied: C:\Program Files\AdoptOpenJDK\jre-8.0.282.8-hotspot
. This file that shows up was a previous version that I had removed.
I tried reinstalling everything, and I also checked the JAVA_HOME environment variable, which is set to C:\Program Files\AdoptOpenJDK\jdk-15.0.2.7-hotspot\
. I've also relaunched the terminal and rebooted my computer. I'm using Git Bash as my shell, if that's anything relevant. Any advice on how to change the supplied javaHome?
Here are some relevant screenshots:
Result of gradle build
Result of java -version
JAVA_HOME environment variable
My (very sketchy) solution is to make a copy of the existing jre15 folder I have and rename it to jre-8.0.282.8-hotspot
. I can build and run my program now, but it just seems very sketch.
One year update: I asked my prof when classes started when he said this solution was actually pretty ok and would suffice for the semester.
I got the following message: Failed to complete Gradle execution. Cause: Supplied javaHome is not a valid folder. You supplied: C:\Program Files\Java\jdk1.7.0_45
One of my coworkers updated their version of the JDK, and has been having nothing but issues. "Supplied javaHome is not a valid folder. You supplied: " We think we’ve changed the right locations. Where else can we look? It works from the command line using gradlew build, etc.
edited Expected Behavior Gradle Daemon is able to launch successfully. Current Behavior Gradle Daemon does not start and fails with the message Supplied javaHome must be a valid directory. You supplied: /usr/lib/jvm/zulu8-ca-amd64
What appears to be happening with Gradle 7 is that when the build starts it attempts to check if an existing daemon can be used, in that check it appears to use the Java installation directory from a previous build to check if it matches what is requested.
I had a similar problem building a Java app on GitHub Actions. Once I upgraded from Java 11 to Java 16 I started to get the same error as you.
In my case it turned out to be a caching problem. I was caching two directories:
~/.gradle
(on windows this should be something like C:\Users\username\.gradle
)project/.gradle
(this one is the gradle directory that is local to my app project).Invalidating the caches fixed the issue for me.
I had a similar problem after uninstalling a Java version with Gradle deamon running. Stopping the deamon fixed the issue for me:
gradle --stop
(Probably, a cross-platform equivalent of Miguel's solution)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With