Gradle is trying to use a JDK that has been uninstalled from my system

I’m fairly inexperienced with Gradle and am trying to figure out why a .bat script that was generated by an IDE I’m using keeps trying to use the wrong JDK. The trouble comes when the bat script tries to execute the following command:

"C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot/bin/java.exe" "-Xmx64m" "-Xms64m" "-Dorg.gradle.appname=gradlew" -classpath "D:\dev\starling2\game\2022\androidExportTest\android\build\\gradle\wrapper\gradle-wrapper.jar" org.gradle.wrapper.GradleWrapperMain

This causes the following error:


FAILURE: Build failed with an exception.

* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk1.8.0_151\bin\java.exe

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

I don’t know why Gradle is looking for Java in C:\Program Files\Java\jdk1.8.0_151\bin\java.exe. I want it to use the OpenJDK 11 installation at C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot. The JAVA_HOME is set to point to the OpenJDK 11 installation so I would have expected Gradle to look there. I also tried setting javaHome but that is being ignored too.

You should at least provide the full stacktrace as recommended by the error message and maybe also have a look at the info log to already see yourself what is happening.

All the stack trace shows is the Jvm failing to run because it cannot find the path. And as far as I can tell from the Gradle docs, the logs are just what is printed to the console when Gradle runs. Here’s the full output when I run with --stacktrace and --info:

D:\dev\starling2\game\2022\androidExportTest\android\build>"C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot/bin/java.exe" "-Xmx64m" "-Xms64m"   "-Dorg.gradle.appname=gradlew" -classpath "D:\dev\starling2\game\2022\androidExportTest\android\build\\gradle\wrapper\gradle-wrapper.jar" org.gradle.wrapper.GradleWrapperMain --stacktrace  --info
Initialized native services in: C:\Users\kitfox\.gradle\native
Initialized jansi services in: C:\Users\kitfox\.gradle\native

FAILURE: Build failed with an exception.

* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk1.8.0_151\bin\java.exe

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.internal.jvm.JavaHomeException: The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk1.8.0_151\bin\java.exe
        at org.gradle.internal.jvm.Jvm.findExecutable(Jvm.java:183)
        at org.gradle.internal.jvm.Jvm.getJavaExecutable(Jvm.java:208)
        at org.gradle.internal.jvm.Jvm.forHome(Jvm.java:119)
        at org.gradle.launcher.daemon.context.DaemonCompatibilitySpec.javaHomeMatches(DaemonCompatibilitySpec.java:64)
        at org.gradle.launcher.daemon.context.DaemonCompatibilitySpec.whyUnsatisfied(DaemonCompatibilitySpec.java:40)
        at org.gradle.launcher.daemon.context.DaemonCompatibilitySpec.isSatisfiedBy(DaemonCompatibilitySpec.java:35)
        at org.gradle.launcher.daemon.context.DaemonCompatibilitySpec.isSatisfiedBy(DaemonCompatibilitySpec.java:25)
        at org.gradle.launcher.daemon.client.DefaultDaemonConnector.getCompatibleDaemons(DefaultDaemonConnector.java:192)
        at org.gradle.launcher.daemon.client.DefaultDaemonConnector.connectToIdleDaemon(DefaultDaemonConnector.java:157)
        at org.gradle.launcher.daemon.client.DefaultDaemonConnector.connect(DefaultDaemonConnector.java:125)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:144)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:98)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:57)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:210)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:275)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:247)
        at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:82)
        at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:30)
        at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:92)
        at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:38)
        at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:44)
        at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:26)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:41)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:26)
        at org.gradle.launcher.cli.DefaultCommandLineActionFactory$WithLogging.execute(DefaultCommandLineActionFactory.java:240)
        at org.gradle.launcher.Main.doAction(Main.java:35)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:50)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:31)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:35)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)


* Get more help at https://help.gradle.org

Well, that it does not tell you more, does not say it does not tell others more. :wink:
Check the JDK settings for Gradle in your IDE, do you maybe there have the old JDK still configured?

I’m running this from the command line, so the IDE is not involved. I had a look at Gradle’s source code which made me think that Java’s system properties might be wrong, but when I dump those they’re correct too.

Gradle’s Jvm object is created with the following code, but I;m having trouble figuring out what calls the create() method:

org.gradle.internal.jvm.Jvm

    private static Jvm create(File javaBase, @Nullable String implementationJavaVersion, @Nullable JavaVersion javaVersion) {
        Jvm jvm = new Jvm(OperatingSystem.current(), javaBase, implementationJavaVersion, javaVersion);
        Jvm current = current();
        return jvm.getJavaHome().equals(current.getJavaHome()) ? current : jvm;
    }

I’ve uninstalled the old version of Java from my computer and am now searching everything I can think of to try and figure out where Gradle is pulling C:\Program Files\Java\jdk1.8.0_151\bin\java.exe from.

I did a grep on my user directory and came up with a file called ./gradle/daemon/7.2/registry.bin that appears to contain a string with the invalid path. It does not appear to be a text file. Could this be it, and how would I change it?

Well, I backed up and then deleted the registry.bin file and now I am able to compile my project. Gradle generated a new registry.bin which now has the correct path in it.

I’m running this from the command line, so the IDE is not involved.

Sorry, must have misinterpreted or misrememberd when you talked about IDE in the original post.

Could this be it, and how would I change it?

Actually I wouldn’t have thought so, that’s just the registry of running (or recently running) Gradle daemons so that the CLI can find an appropriate still running daemon if one is present already.
After quitting all Gradle daemons, you can safely delete the whole <GRADLE_USER_HOME>/daemon/ directory, it only contains that registry and the daemon log files.

But as this fixed it for you, I’d suggest you open an issue on GitHub with what happened and the stack trace. Maybe there is a bug somewhere that gets confused if the registry still contains an entry for a dead daemon with a now removed JDK that should be fixed.