Java Toolchain for Java 18

I’m currently working on some code for a book and for the book I want to use the latest version of Java (we still have a year, so this is a moving target). For now I want to be able to use Java 18. Although, officially, Java 18 isn’t supported I wanted to try to see if I could get a toolchain up-and-running.

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(18)
        vendor = JvmVendorSpec.matching("Eclipse Adoptium")
    }
}

The above is what I have as a toolchain, however it doesn’t detect my Java version. It does scan it when I look at the log-output. That is when running with --info.

Selected primary task 'build' from project :
Starting process 'command '/usr/libexec/java_home''. Working directory: /Users/marten/.gradle/daemon/7.3 Command: /usr/libexec/java_home -V
Successfully started process 'command '/usr/libexec/java_home''
Starting process 'command '/Users/marten/.sdkman/candidates/java/16.0.2-tem/bin/java''. Working directory: /Users/marten/.gradle/.tmp/tmp-jvm10306309934603892307probe Command: /Users/marten/.sdkman/candidates/java/16.0.2-tem/bin/java -cp . JavaProbe
Successfully started process 'command '/Users/marten/.sdkman/candidates/java/16.0.2-tem/bin/java''
Starting process 'command '/Users/marten/.sdkman/candidates/java/11.0.12-tem/bin/java''. Working directory: /Users/marten/.gradle/.tmp/tmp-jvm6310211890516680930probe Command: /Users/marten/.sdkman/candidates/java/11.0.12-tem/bin/java -cp . JavaProbe
Successfully started process 'command '/Users/marten/.sdkman/candidates/java/11.0.12-tem/bin/java''
Starting process 'command '/Users/marten/.sdkman/candidates/java/8.0.302-tem/bin/java''. Working directory: /Users/marten/.gradle/.tmp/tmp-jvm10361932553313144534probe Command: /Users/marten/.sdkman/candidates/java/8.0.302-tem/bin/java -cp . JavaProbe
Successfully started process 'command '/Users/marten/.sdkman/candidates/java/8.0.302-tem/bin/java''
Starting process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java''. Working directory: /Users/marten/.gradle/.tmp/tmp-jvm11829486258542520882probe Command: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java -cp . JavaProbe
Successfully started process 'command '/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java''
Starting process 'command '/Users/marten/.sdkman/candidates/java/18.ea.23-open/bin/java''. Working directory: /Users/marten/.gradle/.tmp/tmp-jvm3813190731550797528probe Command: /Users/marten/.sdkman/candidates/java/18.ea.23-open/bin/java -cp . JavaProbe
Successfully started process 'command '/Users/marten/.sdkman/candidates/java/18.ea.23-open/bin/java''

However it doesn’t find it

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':ch02:copyDependenciesToLibDir'.
> Could not resolve all dependencies for configuration ':ch02:runtimeClasspath'.
   > Failed to calculate the value of task ':ch02:compileJava' property 'javaCompiler'.
      > No compatible toolchains found for request filter: {languageVersion=18, vendor=matching('Eclipse Adoptium'), implementation=vendor-specific} (auto-detect true, auto-download true)

Do I have to wait for a gradle version that supports Java 18 before I can use that to build with or is there a workaround (I could probably force the JAVA_HOME to that but I rather not do that).

Alright, I apparently didn’t have enough coffee yet. I used the wrong vendor :man_facepalming: . It should have been Oracle and not (yet) Eclipse Adoptium.

I should have run gradle -q javaToolchains, take some coffee and look at the output (which was quite obvious in hindsight).