0

I am trying to compile using mvn verify but I am getting the error stated below:

Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.6.1:generateStubs (groovy) on project jenkinsfile-test-shared-library: Error occurred while calling a method on a Groovy class from classpath. InvocationTargetException: startup failed:

[ERROR] General error during conversion: java.lang.NoClassDefFoundError: junit/framework/TestSuite
[ERROR]
[ERROR] java.lang.RuntimeException: java.lang.NoClassDefFoundError: junit/framework/TestSuite
[ERROR] at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1101)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1079)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
[ERROR] at org.codehaus.groovy.tools.javac.JavaStubCompilationUnit.compile(JavaStubCompilationUnit.java:93)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.gmavenplus.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:275)
[ERROR] at org.codehaus.gmavenplus.mojo.AbstractGenerateStubsMojo.doStubGeneration(AbstractGenerateStubsMojo.java:170)
[ERROR] at org.codehaus.gmavenplus.mojo.GenerateStubsMojo.execute(GenerateStubsMojo.java:72)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

[ERROR] Caused by: java.lang.NoClassDefFoundError: junit/framework/TestSuite
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
[ERROR] at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
[ERROR] at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:545)
[ERROR] at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:185)
[ERROR] at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:170)
[ERROR] at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:126)
[ERROR] at org.codehaus.groovy.control.ResolveVisitor.resolveToOuter(ResolveVisitor.java:676)
[ERROR] at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:313)
[ERROR] at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1236)
[ERROR] at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:176)
[ERROR] at org.codehaus.groovy.tools.javac.JavaStubCompilationUnit$1.call(JavaStubCompilationUnit.java:66)
[ERROR] at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
[ERROR] ... 33 more

[ERROR] Caused by: java.lang.ClassNotFoundException: junit.framework.TestSuite
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[ERROR] ... 55 more
[ERROR]
[ERROR] 1 error

...............................................................

Also specifying my dependency tree:

$ mvn dependency:tree |grep groovy

[INFO] |  +- org.kohsuke.stapler:stapler-groovy:jar:1.254:test
[INFO] |  |  \- org.kohsuke:groovy-sandbox:jar:1.10:test
[INFO] |  +- com.cloudbees:groovy-cps:jar:1.16:test
[INFO] +- org.codehaus.groovy:groovy-all:jar:2.4.11:compile
[INFO] +- org.spockframework:spock-core:jar:1.1-groovy-2.4:test
kriegaex
  • 63,017
  • 15
  • 111
  • 202
Subhojoy Dey
  • 3
  • 1
  • 3
  • Welcome to SO. Please learn how to ask questions here, reading the [MCVE](https://stackoverflow.com/help/mcve) article. Thank you. Afterwards, click "Edit" and update your question with the Maven POM and example application and test classes to reproduce your problem. – kriegaex Nov 22 '21 at 14:54
  • As for the error message as such: If Maven complains that class `junit.framework.TestSuite` is missing, how about adding JUnit 4 with test scope to your POM, ideally the latest [version 4.13.2](https://search.maven.org/artifact/junit/junit/4.13.2/jar)? BTW, Spock 1.3 is a better choice for JUnit 4 than the outdated 1.1. But Spock 2.0 (JUnit 5) and 2.1-M2 are also available. – kriegaex Nov 22 '21 at 14:56
  • I already had Junit added as test scope to my POM, tried changing the version from 4.8 to 4.13.2 as you mentioned. But the error still remains the same. Yes, Spock higher versions seem to be good. will test them once this issue is resolved. – Subhojoy Dey Nov 23 '21 at 04:21
  • Thank you for all the help @kriegaex . I will surely follow the rules from now on. – Subhojoy Dey Nov 26 '21 at 04:37

1 Answers1

0

Issue fixed. There was a duplicate entry in pom.xml. removing it fixed the problem


Update by kriegaex, copied from a comment by Subhojoy Dey for better readability:

<plugin>
  <groupId>org.codehaus.gmavenplus</groupId>
  <artifactId>gmavenplus-plugin</artifactId>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
</plugin>

This was defined multiple times, deleting this made the issue go. Maybe some version mismatched happened and the error popped up.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
Subhojoy Dey
  • 3
  • 1
  • 3
  • It would be interesting to learn what exactly the duplicate entry was and how it could lead to the issue you described. Please publish your POM (or a minimal version of it, reproducing the problem) in order to educate others who might experience the same problem in the future. This way, you can return something useful to the community you asked for help. Thank you. – kriegaex Nov 23 '21 at 09:10