You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Grab('info.picocli:picocli-groovy:4.7.0')
@GrabConfig(systemClassLoader=true)
@Command(name="myScript",
mixinStandardHelpOptions=true, // add --help and --version options
description="@|bold Groovy script|@ @|underline picocli|@ example")
@picocli.groovy.PicocliScript2importgroovy.transform.Fieldimport staticpicocli.CommandLine.*@Option(names= ["-c", "--count"], description="number of repetitions")
@Fieldint count =1;
// PicocliBaseScript2 prints usage help or version if requested by the user
count.times {
println"hi"
}
// the CommandLine that parsed the args is available as a propertyassertthis.commandLine.commandName =="myScript"
with picocli 4.7.0 I get
;groovy test.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error registering runner class 'org.codehaus.groovy.testng.TestNgRunner'
java.lang.IllegalStateException: Error registering runner class 'org.codehaus.groovy.testng.TestNgRunner'
at groovy.grape.GrapeIvy$_processRunners_closure6.doCall(GrapeIvy.groovy:414)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1009)
at groovy.lang.Closure.call(Closure.java:418)
at groovy.lang.Closure.call(Closure.java:434)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2388)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2373)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2414)
at groovy.grape.GrapeIvy.processRunners(GrapeIvy.groovy:409)
at groovy.grape.GrapeIvy.processMetaInfServices(GrapeIvy.groovy:386)
at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:289)
at groovy.grape.Grape$1.run(Grape.java:172)
at groovy.grape.Grape$1.run(Grape.java:158)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
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:377)
at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:896)
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.run(GroovyShell.java:392)
at groovy.lang.GroovyShell.run(GroovyShell.java:382)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:649)
at groovy.ui.GroovyMain.run(GroovyMain.java:389)
at groovy.ui.GroovyMain.access$1400(GroovyMain.java:67)
at groovy.ui.GroovyMain$GroovyCommand.process(GroovyMain.java:313)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:141)
at groovy.ui.GroovyMain.main(GroovyMain.java:114)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:132)
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.codehaus.groovy.testng.TestNgRunner@476ec9d0' with class 'org.codehaus.groovy.testng.TestNgRunner' to class 'org.apache.groovy.plugin.GroovyRunner'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:424)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:335)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:255)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:621)
at groovy.grape.GrapeIvy$_processRunners_closure6.doCall(GrapeIvy.groovy:412)
... 45 more
1 error
;groovy --version
Groovy Version: 4.0.5 JVM: 17.0.5 Vendor: Red Hat, Inc. OS: Linux
The same example with picocli version 4.6.3 works fine.
The text was updated successfully, but these errors were encountered:
The issue is that you are getting Groovy from Groovy 4 but groovy-testng from the Groovy 2.4.21 groovy-all jar. It's a combination of the maven coordinate change from org.codehaus.groovy to org.apache.groovy plus possibly the fact that testng became an optional module with Groovy 4.
Thank you @paulk-asert for pointing that out, and for providing the workaround!
@GrabExclude('org.codehaus.groovy:groovy-all')
This issue was caused by #1613, which made picocli-groovy bring in the (old) org.codehaus.groovy:groovy-all dependency. Since any Groovy script will already need to have a Groovy environment in which it is run, picocli-groovy should not try to bring in Groovy op top of that.
This is fixed in the main branch now and the fix will be part of the picocli 4.7.1 release. Until then, please use the above workaround.
Running the example-application from https://picocli.info/#_groovy_scripts
with picocli
4.7.0
I getThe same example with picocli version
4.6.3
works fine.The text was updated successfully, but these errors were encountered: