Gradle does not detect Java Toolchains on Windows

Currently we don’t have access out on the Internet.
So I have made available OpenJDK 11, 14, 15 and 16 from AdoptOpenJDK.

On Linux it discovers these, so it does not try to download from AdoptOpenJDK.

On Windows it tries to download, which fails since it cannot access Internet. Seems it does not detect the JDK I have there.

C:\Program Files\Java\jdk-11
C:\Program Files\Java\jdk-14
C:\Program Files\Java\jdk-15
C:\Program Files\Java\jdk-16

All of these are unpacked from the ZIP archive.

In addition I have AdoptOpenJDK OpenJDK 11 installed through MSI.
C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot

Gradle only detects the versions of OpenJDK installed on Windows, none of those unpacked from archive

 + AdoptOpenJDK 11.0.11
     | Location:           C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot
     | Language Version:   11
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Current JVM

The detection mechanism must be different between Linux and Windows. On Linux it detects those OpenJDK unpackaged from archives.

Yes, that’s right.
It detects from several standard places that some SDK managers or OS packages use or from the Windows registry.
Even the 11.0.11 it detected is not detected because you installed it, but because you run Gradle with it.
Where the algorithm looks for Java installations is listed in the documentation.
If you installed the AdoptOpenJdk packages from MSI and in the installer chose to set the Oracle registry keys, they would have been detected.
Alternatively you can tell it to look in those paths for JDKs like also documented.

I am not sure what documentation you are referring to.
https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection

How do I get Gradle to detect available JDKs on Windows? From the documentation there is nothing mentioned of any configuration for Toolchain to work on Windows.
Other that to specify custom toolchain locations
org.gradle.java.installations.paths=C:\Program Files\Java\jdk-11,C:\Program Files\Java\jdk-14,C:\Program Files\Java\jdk-15,C:\Program Files\Java\jdk-16

Hm, ok, I had it more detailed in memory.
But as I said, the “standard location” on Windows afair is where it is registered in the registry.
I just installed a fresh windows box yesterday, used the MSI installers and checked the option to write the registry entries, and all are detected by Gradle.

Ok. So then all JDKs I install with MSI will be detected.
I will try that.

I just tried to unpack the JDKs under C:\Users\myuser\.gradle/jdks
Running gradlew.bat -q javaToolchains does not list them, but the build does not fail. The toolchain I have defined in build.gradle for JDK-14 is used.

I installed OpenJDK 11, 14, 15 and 16 using the MSI installers.
Checked to update registry for all of them.
Running Gradle with JDK 11. JDK 11 also has the JAVA_HOME.
Gradle now lists all these as toolchains.

The thing is, I wanted them in the .gradle/jdks directory on Windows.
When building with Docker I mount the .gradle directory, that way the docker image also has access to these toolchains.
Now I would need to install all the JDKs in the Docker image with MSI. Not an easy feat. My current docker image in Windows just unpacks archives, because installing silent MSI in docker build didn’t work.

Well, that’s totally new information you didn’t mention before. :wink:
After successfully unpacking to $GRADLE_USER_HOME/jdks create a file called provisioned.ok in the respective directory.
The marker is created after the unpacking is finished and thus ensures that no half-unpacked jdk is used, either because of the unpacking failing or because of currently being in the process of unpacking.