Project Loom build fails with NoSuchElementException

I’m trying to build my project via the Project Loom JDK but it fails with the following exception on GitHub Actions:

Execution failed for task ‘:compileJava’.

Error while evaluating property ‘javaVersion’ of task ‘:compileJava’
No value present

Caused by: Error while evaluating property ‘javaVersion’ of task ‘:compileJava’
Caused by: java.util.NoSuchElementException: No value present
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.query(
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.lambda$findMatchingToolchain$0(
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.lambda$findMatchingToolchain$1(

I’m using Gradle 7.1, JDK 16.0.1 for the runtime of Gradle, Loom 17b7 and the following override:

def jdkNextdir = System.getenv("JDK_NEXT")
if (jdkNextdir != null) {
    logger.lifecycle("JDK override: " + jdkNextdir);
    compileJava.options.fork = true
    compileTestJava.options.fork = true
    compileJava.options.forkOptions.executable = jdkNextdir + "/bin/javac"
    javadoc.executable = jdkNextdir + "/bin/javadoc"
    test.executable = jdkNextdir + "/bin/java"
    compileTestJava.options.forkOptions.executable = compileJava.options.forkOptions.executable

Note that the same override trick works with JDK 17 EA and JDK 18 EA.

Please advise.