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: org.gradle.api.internal.tasks.properties.PropertyEvaluationException: Error while evaluating property ‘javaVersion’ of task ‘:compileJava’
at org.gradle.api.internal.tasks.properties.InputParameterUtils.prepareInputParameterValue(InputParameterUtils.java:33)
Caused by: java.util.NoSuchElementException: No value present
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.query(JavaToolchainQueryService.java:74)
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.lambda$findMatchingToolchain$0(JavaToolchainQueryService.java:62)
at org.gradle.jvm.toolchain.internal.JavaToolchainQueryService.lambda$findMatchingToolchain$1(JavaToolchainQueryService.java:62)

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.