Detection of Java Toolchains on Linux: Installed JDK not detected

Gradle is only able to detect the OpenJDK I have manually downloaded from AdoptOpenJDK, and unpacked under /usr/java/.

https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection

These OpenJDK I have unpacked are listed as

 + AdoptOpenJDK 11.0.11
     | Location:           /usr/java/jdk-11.0.11+9
     | Language Version:   11
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Current JVM

 + AdoptOpenJDK 11.0.9.1
     | Location:           /usr/java/jdk-11.0.9.1+1
     | Language Version:   11
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Common Linux Locations

 + AdoptOpenJDK 14.0.2
     | Location:           /usr/java/jdk-14.0.2+12
     | Language Version:   14
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Common Linux Locations

 + AdoptOpenJDK 15.0.1
     | Location:           /usr/java/jdk-15.0.1+9
     | Language Version:   15
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Common Linux Locations

 + AdoptOpenJDK 16
     | Location:           /usr/java/jdk-16+36
     | Language Version:   16
     | Vendor:             AdoptOpenJDK
     | Is JDK:             true
     | Detected by:        Common Linux Locations

 + Oracle JDK 1.8.0_221
     | Location:           /usr/java/jdk1.8.0_221
     | Language Version:   8
     | Vendor:             Oracle
     | Is JDK:             true
     | Detected by:        Common Linux Locations

 + Oracle JDK 1.8.0_181
     | Location:           /usr/java/jdk1.8.0_181
     | Language Version:   8
     | Vendor:             Oracle
     | Is JDK:             true
     | Detected by:        Common Linux Locations

Gradle does not detect the OpenJDK I have installed through the Linux package manager, and those are installed under /usr/lib64/jvm/.

What are these Common Linux Locations?
The /usr/lib64/jvm/ should be a part of these locations.

I have been digging around in the Gradle Code.
These are the Linux locations

this(factory, OperatingSystem.current(), "/usr/lib/jvm", "/usr/java");

Defined in LinuxInstallationSupplier.java.
A fix should be done there, to use /usr/lib64/jvm instead of /usr/lib/jvm, or in addition to.

A Pull Request have been made for this.

1 Like

I don’t know which Linux distribution you’re using, but /usr/lib/jvm is the default installation path for packaged JVMs in Ubuntu, so it should be kept.

I am using OpenSUSE.
I have submitted a pull request to add /usr/lib64/jvm as a Linux Toolchain locations.

I justed checked with Fedora. It also stores the OpenJDK in /usr/lib/jvm.
Not sure why it is different on OpenSUSE.