nextflow-io / nextflow

A DSL for data-driven computational pipelines
http://nextflow.io
Apache License 2.0
2.7k stars 622 forks source link

Enable build with Java 21 #5029

Closed pditommaso closed 4 months ago

pditommaso commented 4 months ago

Currently Nextflow runs on Java 11 and later up to Java 22 (included).

However the build process is still using Java 19 as defined by the following entry in the Gradle build

https://github.com/nextflow-io/nextflow/blob/de13de80b7f7eaf92e16893fb7b7fd30d539a005/build.gradle#L71-L71

The goal of this issue is to upgrade build toolchaing to Java 21 which enables the use of modern JVM features such as virtual threads.

However, when using any Java version >= 21 the following *runtime* error is reported:

Execution error (ClassNotFoundException) at
jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).
java.util.SequencedCollection

This looks caused by the new SequencedCollection interface introduced in Java 21 that's retroffied in the collection API.

Ideally the target compatibility setting should prevent this, but it looks it's ignored.

The following link reports a similar error in Clojure:

https://aphyr.com/posts/369-classnotfoundexception-java-util-sequencedcollection

pditommaso commented 4 months ago

It works with no problem using as simple project https://github.com/pditommaso/groovy-java21-poc

pditommaso commented 4 months ago

Wonder if it could be an error with the Grengine script parser

java.lang.NoClassDefFoundError: java/util/SequencedCollection
    at nextflow.script.WorkflowDef.collectInputs(WorkflowDef.groovy:127)
    at nextflow.script.WorkflowDef.run0(WorkflowDef.groovy:199)
    at nextflow.script.WorkflowDef.run(WorkflowDef.groovy:188)
    at nextflow.script.BindableDef.invoke_a(BindableDef.groovy:51)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at nextflow.script.BaseScript.run0(BaseScript.groovy:198)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
    at nextflow.script.BaseScript.run(BaseScript.groovy:209)
    at nextflow.script.ScriptParser.runScript(ScriptParser.groovy:236)
    at nextflow.script.ScriptRunner.run(ScriptRunner.groovy:243)
    at nextflow.script.ScriptRunner.execute(ScriptRunner.groovy:138)
    at nextflow.cli.CmdRun.run(CmdRun.groovy:372)
    at nextflow.cli.Launcher.run(Launcher.groovy:503)
    at nextflow.cli.Launcher.main(Launcher.groovy:657)
Caused by: java.lang.ClassNotFoundException: java.util.SequencedCollection
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
pditommaso commented 4 months ago

I've tried setting the script compiler target bytecode version, but still no joy https://github.com/nextflow-io/nextflow/pull/5030/commits/8bcdf49a700b74f5b738e179be48a40e21620269

pditommaso commented 4 months ago

Unable to replicate the problem with the POC.

pditommaso commented 4 months ago

It turns out ScriptParser classes uses Groovy shell, as well

https://github.com/nextflow-io/nextflow/blob/29d6f1dfa987164b55d9077c9218b55041d8c960/modules/nextflow/src/main/groovy/nextflow/script/ScriptParser.groovy#L166-L166

pditommaso commented 4 months ago

Ok, the problem is the @Delegate annotation for List

https://github.com/pditommaso/groovy-java21-poc/blob/4a5c8951ab93cc02a4052b6613fabdd6c772ed50/app/src/main/groovy/org/example/ListDelegate.groovy#L12-L12