Skip to content

Example GroovyScript throws IllegalStateException registering runner class TestNgRunner #1885

Closed

Description

@mkutz

Running the example code at https://picocli.info/#_groovy_scripts results in the following exception:

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:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	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:2386)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2371)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2412)
	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(Native Method)
	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:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	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@7afbf561' 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

Running groovy -v returns

Groovy Version: 4.0.6 JVM: 11.0.17 Vendor: Eclipse Adoptium OS: Linux

Activity

  1. remkop commented on Nov 29, 2022

    @remkop
    Owner

    Thank you for raising this! Looks similar to #1874.

    I hope I will have time to look at this the coming weekend.

    Note to self: potential causes:

  2. paulk-asert commented on Jan 24, 2023

    @paulk-asert

    I am not sure how you are setting the classpath for your script. Since the maven coordinates changed from org.codehaus.groovy to org.apache.groovy with Groovy 4, you are possibly getting both Groovy 2.4.x (from picocli dependencies) along with Groovy 4 runners. The Groovy 4 testng runner has full package of org.apache.groovy.plugin.testng.TestNgRunner. Your stacktrace is showing the old 2.4.x runner org.codehaus.groovy.testng.TestNgRunner. You will want to exclude that from your classpath.

  3. remkop commented on Jan 25, 2023

    @remkop
    Owner

    Thank you @paulk-asert for pointing that out, and for providing the workaround (in #1874)!

    @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.

  4. added this to the 4.7.1 milestone on Jan 25, 2023
  5. added a commit that references this issue on Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions