| Priority |
Normal |
| Type | Feature |
| State | Open |
| Assignee | Peter Gromov |
| Subsystem | Groovy/Grails |
| Affected versions |
No affected versions
|
| Fix for |
No fix versions
|
|
|
A compilation error prevent to run the following groovy script:
import org.apache.commons.collections.primitives.ArrayIntList
@Grab(group='commons-primitives', module='commons-primitives', version='1.0')
def createEmptyInts() { new ArrayIntList() }
def ints = createEmptyInts()
ints.add(0, 42)
assert ints.size() == 1
assert ints.get(0) == 42
Note: If I put the whole code between
evaluate """
// here goes the code
"""
the local grapes repository is populated with the the requested jars and scripts is running.
There is a workaround to make the script instead of 'evaluate()'
Thanks
The compilation error message is:
Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Information:0 warnings
Error:java.lang.NoClassDefFoundError: org/apache/ivy/core/report/ResolveReportat java.lang.Class.getDeclaredMethods0(Native Method)at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)at java.lang.Class.getDeclaredMethods(Class.java:1791)at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:83)at java.security.AccessController.doPrivileged(Native Method)at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:78)at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:33)at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:20)at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:252)at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:341)at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:291)at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2890)at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:154)at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:170)at groovy.grape.GrapeIvy.$getStaticMetaClass(GrapeIvy.groovy)at groovy.grape.GrapeIvy.<init>(GrapeIvy.groovy:49)at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)at java.lang.reflect.Constructor.newInstance(Constructor.java:513)at java.lang.Class.newInstance0(Class.java:355)at java.lang.Class.newInstance(Class.java:308)at groovy.grape.Grape.getInstance(Grape.java:105)at groovy.grape.Grape.grab(Grape.java:140)at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:181)at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:268)at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:798)at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:40)at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:121)Caused by: java.lang.ClassNotFoundException: org.apache.ivy.core.report.ResolveReportat java.net.URLClassLoader$1.run(URLClassLoader.java:200)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:188)at java.lang.ClassLoader.loadClass(ClassLoader.java:307)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)at java.lang.ClassLoader.loadClass(ClassLoader.java:252)at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)... 31 more
Could you file a separate JIRA issue. How is the Groovy library in your module configured, which jars does it include?
What I really need is for IDEA to add what's mentioned in @Grab's on the module classpath. Currently, I need to mention the dependencies in the module pom.xml too, to get them added to IDEA module on project import.
In addition, what does your full classpath look like? What version of groovy are you using?
I am not sure though, if this plugin will solve my problem. The intention for Grab'ing dependencies, will that also end up putting them on the module classpath?
Does it make sense to add those @Grab dependencies to the module classpath? If two .groovy files @grab different versions of a dependency, which one should be added to the classpath?
Are you (IDEA) capable of having the dependencies added locally to the script? I mean, that will be hard to follow with the classes that the scripts uses etc., won't it?
Adding the dependencies to classpath is exactly what the plugin tries to do. Otherwise IDEA won't be able to compile the project sometimes. As for the different versions... I don't know a solution.
Having special dependencies for scripts is very tricky but possible. But the dependent classes won't see them. Alas.
Looking forward to testing a version of the plugin that works :-) Or is it me, that needs to cleanup the asm dependency versions in my module?
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<version>2.1.0</version>
</dependency>
to my pom for the module, and that made the plugin work. Afterward I deleted the Grab'ed dependencies from the pom and the Groovy code was still green. Looking at module dependencies I see them with "Grab: " in front. Nice.
Will this be part of 9.0.2 or something?
I don't think that Ivy should be part of the plugin. I wonder how running your scripts worked when there was no Ivy in the classpath. I'll investigate this and make the plugin behave in the same way
groovy FooBar.groovy
I guess groovy 1.7.2 includes ivy in its classpath.