Grape not supported anymore on Nextflow version v24.0.7.0-edge
Bug report
The following piece of code works in v24.06,0-edge but not in the latest version:
@Grab(group='org.apache.commons', module='commons-text', version='1.12.0')
import org.apache.commons.text.similarity.LevenshteinDistance
Program output
ERROR ~ Class definition not found: org/apache/ivy/util/MessageLogger
...
Aug-17 20:03:02.815 [main] ERROR nextflow.cli.Launcher - @unknown
java.lang.NoClassDefFoundError: org/apache/ivy/util/MessageLogger
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:413)
at java.base/java.lang.Class.forName(Class.java:404)
at groovy.grape.Grape.getInstance(Grape.java:124)
at groovy.grape.Grape$1.run(Grape.java:161)
at groovy.grape.Grape$1.run(Grape.java:158)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
at groovy.grape.Grape.grab(Grape.java:158)
at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:380)
at org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$addPhaseOperationsForGlobalTransforms$5(ASTTransformationVisitor.java:374)
at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:897)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:692)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:666)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:373)
at groovy.lang.GroovyClassLoader.lambda$parseClass$2(GroovyClassLoader.java:316)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163)
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:572)
at groovy.lang.GroovyShell.parse(GroovyShell.java:585)
at groovy.lang.GroovyShell.parse(GroovyShell.java:639)
at groovy.lang.GroovyShell.parse(GroovyShell.java:643)
at nextflow.script.ScriptParser.parse0(ScriptParser.groovy:175)
at nextflow.script.ScriptParser.parse(ScriptParser.groovy:206)
at nextflow.script.ScriptRunner.parseScript(ScriptRunner.groovy:229)
at nextflow.script.ScriptRunner.execute(ScriptRunner.groovy:136)
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: org.apache.ivy.util.MessageLogger
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:525)
... 29 common frames omitted
Environment
- Nextflow version: v24.0.7.0-edge
- Java version: java 21.0.1 2023-10-17 LTS
- Operating system: Ubuntu
- Bash version: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
I think it's a side effect of the new launcher distribution. https://github.com/nextflow-io/nextflow/pull/3395
However, @Grab was never expected to be supported "officially" by nextflow. It's time to sunsetting it.
I see, thank you for the answer, what is an alternative? I found no documentation about adding Groovy dependencies to a process, and Grape was really that it worked out of the box.
I would try moving this code into a Groovy script in the lib directory. If that doesn't work, I think you can also include a JAR file in the lib directory and it will be added to the classpath.
Docs: https://nextflow.io/docs/latest/sharing.html#utility-code
Hi Ben, thanks for the input. Doesn't Google Batch require Tower in order to have the lib directory considered? If that's not the case, then including the jar file is a good enough alternative I guess.
The lib directory should work regardless of where you run your pipeline.