Groovyc and ivy

Hi,

I'm fairly new to groovy. I'm unable to grok how to get it working seamlessly in Intellij...

I get this:

Error:Groovyc: Cannot @Grab without Ivy, please add it to your module dependencies (NoClassDefFoundError: org/apache/ivy/core/settings/IvySettings)

when I build my project. I've downloaded and added ivy 2.4.0 to my project, but I still get the above.

I'm on OSX 10.10.5 and Intellij ultimate 14.1.5, using Java 8.

Any advice?

Paul

13 comments
Comment actions Permalink

Is Ivy dependency added to the same module that uses @Grab annotation? Could you please attach a screenshot of that module's dependencies (File | Project Structure)?

0
Comment actions Permalink

There you go, attached.

Ivy seems to be there several times:

  1. From alt-enter on the @grab line
  2. From pom.xml
  3. From the .jar that I downloaded and added.


Of course I've tried already with only one.



Attachment(s):
module-ivy.png
0
Comment actions Permalink

How many modules does your project have?

Could you please go to "File | Settings | Build, Execution, Deployment | Compiler", and add the following to the build process VM options: -Dgroovyc.reuse.compiler.classes=false
After that, please invoke compilation a couple of times. Does this help?

0
Comment actions Permalink
  1. Just the one module.
  2. Sorry, now I get a stack trace:

Information:Groovyc: Groovyc stub generation failed
Information:Groovyc: java.lang.RuntimeException: No suitable ClassLoader found for grab
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
 at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:184)
 at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
 at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:251)
 at groovy.grape.Grape.grab(Grape.java:167)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:378)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:321)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
 at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:58)
 at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:116)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:132)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:148)
 at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.access$000(InProcessGroovyc.java:48)
 at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:77)
 at org.jetbrains.jps.incremental.groovy.InProcessGroovyc$1.call(InProcessGroovyc.java:74)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)



The lines for Grab are:
 
@GrabConfig(systemClassLoader = true)
@Grab('log4j:log4j:1.2.17')
@Grab('org.apache.ivy:ivy:2.4.0')
0
Comment actions Permalink

Thanks for the code sample. It might be caused by systemClassLoader parameter. Can you try compiling without it?
Another thing to try is to replace additional VM options with this: -Dgroovyc.in.process=false

0
Comment actions Permalink

hmm.  I'm not sure if this is working, but now I get the below.  The stub generation looks more than a warning.

Information:Groovyc: Groovyc stub generation failed
Information:Groovyc: java.lang.RuntimeException: No suitable ClassLoader found for grab
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
 at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:184)
 at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
 at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:251)
 at groovy.grape.Grape.grab(Grape.java:167)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:378)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:321)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
 at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:58)
 at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:116)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:132)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain(GroovycRunner.java:100)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:70)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130)
Information:19/10/2015 19:00 - Compilation completed with 1 error and 2 warnings in 6s 617ms
Error:Groovyc: java.lang.RuntimeException: No suitable ClassLoader found for grab
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
 at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:184)
 at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
 at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:251)
 at groovy.grape.Grape.grab(Grape.java:167)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:378)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:321)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
 at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:58)
 at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:116)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:132)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain(GroovycRunner.java:100)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:70)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130)
Warning:Groovyc: The global transform for class groovy.grape.GrabAnnotationTransformation is defined in both jar:file:/Users/spsammy/.sdkman/groovy/current/lib/groovy-2.4.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation and jar:file:/Users/spsammy/.m2/repository/org/codehaus/groovy/groovy-all/2.4.4/groovy-all-2.4.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation - the former definition will be used and the latter ignored.
Warning:Groovyc: The global transform for class org.codehaus.groovy.ast.builder.AstBuilderTransformation is defined in both jar:file:/Users/spsammy/.sdkman/groovy/current/lib/groovy-2.4.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation and jar:file:/Users/spsammy/.m2/repository/org/codehaus/groovy/groovy-all/2.4.4/groovy-all-2.4.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation - the former definition will be used and the latter ignored.

The settings are:

  1. I removed the ivy libs except for one (the jar I downloaded)
  2. VM settings: -Dgroovyc.in.process=false
  3. Code is

@GrabConfig(systemClassLoader =true)

@Grab('log4j:log4j:1.2.17')
@Grab('org.apache.ivy:ivy:2.4.0')
0
Comment actions Permalink

Could you please try with systemClassLoader=false?

0
Comment actions Permalink

Looks the same:
Information:Groovyc: Groovyc stub generation failed
Information:Groovyc: java.lang.RuntimeException: No suitable ClassLoader found for grab
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
 at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
 at groovy.grape.GrapeIvy.chooseClassLoader(GrapeIvy.groovy:184)
 at groovy.grape.GrapeIvy$chooseClassLoader.callCurrent(Unknown Source)
 at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:251)
 at groovy.grape.Grape.grab(Grape.java:167)
 at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:378)
 at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:321)
 at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
 at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:58)
 at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:116)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:132)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain(GroovycRunner.java:100)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:70)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130)
Information:19/10/2015 19:14 - Compilation completed successfully with 2 warnings in 7s 520ms
Warning:Groovyc: The global transform for class groovy.grape.GrabAnnotationTransformation is defined in both jar:file:/Users/spsammy/.sdkman/groovy/current/lib/groovy-2.4.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation and jar:file:/Users/spsammy/.m2/repository/org/codehaus/groovy/groovy-all/2.4.4/groovy-all-2.4.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation - the former definition will be used and the latter ignored.
Warning:Groovyc: The global transform for class org.codehaus.groovy.ast.builder.AstBuilderTransformation is defined in both jar:file:/Users/spsammy/.sdkman/groovy/current/lib/groovy-2.4.5.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation and jar:file:/Users/spsammy/.m2/repository/org/codehaus/groovy/groovy-all/2.4.4/groovy-all-2.4.4.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation - the former definition will be used and the latter ignored.

0
Comment actions Permalink

Thanks.
Is it possible for you to provide a sample project where we can reproduce the issue?

0
Comment actions Permalink

Can I email it to you directly? I've cut out parts of the current project, but I'm slightly worried that something proprietary will be accidentally left in.

0
Comment actions Permalink

Just an update for future readers of this thread.

I took my discussion with the very helpful Peter off-thread and into email.  He created a new jar to replace a plugin jar in my intellij.  Now it works!

Thanks Peter Gromov!

Paul

0
Comment actions Permalink

Thanks for the kind words!

If anyone has the same issue, attached is a jar with an experimental fix, compatible with IDEA 14.1.x. One should go to idea/plugins/Groovy/lib and replace the same-named jar with the attached one. That requires IDE restart.



Attachment(s):
groovy-jps-plugin.jar
0
Comment actions Permalink

The change is now present in the last 15.0.2 EAP and will be in the next 14.x bugfix release when it appears.

0

Please sign in to leave a comment.