Toolchain default vendor exclusion

I’m looking for a way to configure the Java toolchain selection process to only choose an Oracle JDK when the project explicitly specifies that it requires an Oracle JDK.

For instance, presuming I have the following JDKs listed in the toolchains (gradle -q javaToolchains):

 + Eclipse Temurin JDK 1.8.0_442-b06
     | Location:           C:\DevApps\Java\jdk8u442-b06
     | Language Version:   8
     | Vendor:             Eclipse Temurin
     | Architecture:       amd64
     | Is JDK:             true
     | Detected by:        Gradle property 'org.gradle.java.installations.paths'

 + OpenJDK 23.0.1+11-39
     | Location:           C:\DevApps\Java\jdk-23.0.1
     | Language Version:   23
     | Vendor:             Oracle
     | Architecture:       amd64
     | Is JDK:             true
     | Detected by:        Current JVM

 + Oracle JDK 1.8.0_281-b09
     | Location:           C:\Program Files\Java\jdk1.8.0_281
     | Language Version:   8
     | Vendor:             Oracle
     | Architecture:       amd64
     | Is JDK:             true
     | Detected by:        Windows Registry

 + Oracle JDK 17.0.14+8-LTS-191
     | Location:           C:\DevApps\Java\jdk-17.0.14
     | Language Version:   17
     | Vendor:             Oracle
     | Architecture:       amd64
     | Is JDK:             true
     | Detected by:        Gradle property 'org.gradle.java.installations.paths'

In a project that is going to be run on a licensed Oracle 1.8 JDK I want this to select the Oracle JDK instead of the Eclipse Temurin instance:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
        vendor = JvmVendorSpec.ORACLE
    }
}

In a project that is not going to be run on a licensed Oracle 1.8 JDK I expect this will select the Eclipse Temurin instance due to Toolchain installations precedence:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
    }
}

What I want to be able to do is, when there is no alternative to an Oracle JDK of the correct version in the detected toolchains, to fail to find a valid JDK. Put differently, only select an Oracle JDK if the vendor is explicitly specified as “Oracle.”

So, this should fail because there’s only the Oracle JDK 17 in the toolchains:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

The purpose of this is to prevent (deter) developers from using an Oracle JDK in a way that violates the Oracle license agreement. We would like to compile against the exact JDK we will be running on (i.e. in Oracle WebLogic), but not all of our applications will be run in that environment, so I’d like to have a fail-safe to help keep us out of Oracle’s crosshairs.

Or maybe I’m overcomplicating this… All of this setup would be optional overhead on everyone’s machines. The development teams should keep in mind where their product is going to be run, and set themselves up accordingly. If they have a matching version of a non-Oracle JDK in their toolchains it will get picked over the Oracle one; and that’s good enough?

I don’t think you can do something like that, or at least I’m not aware of. You would probably need to request this as feature if you need it.

The only thing I could think of is to disable the auto-discovery but configure looking for toolchains in certain environment variables, then the build needing Oracle could be set up to look in environment variables that contain Oracle toolchains and the others to look in the others.