Access javaToolchains from settings.gradle

I would like to include projects depending on the availability of JDKs. And of course don’t include prijects that use a JDK toolchain not available on the system.

Since the inclusion happens in the settings file and javaToolchains task does not seem to be dependant on having the java plugin applied, I believed this is possible.

But I’m not sure anymore after peeking into javaToolchains task source code :

There’s some internal class JavaInstallationRegistry and JvmMetadataDetector that gets injected in this task. But I don’t think I can use these classes (regardless of their internal status) in a settings file, because I don’t know how to get a a reference. And I fear that doing this in the rootProject will be too late to act on the project inclusion.