Priority
Normal
Type
Feature 
State
Open 
Assignee
Peter Gromov 
Subsystem
Groovy/Grails 
Affected versions
Fix for
  • Submitted by   Peter Gromov
    15 months ago (20 May 2009 19:53)
  • Updated by   Per Olesen
    4 months ago (21 Apr 2010 18:42)
  • Jira: IDEA-49022
    (history, comments)
IDEA-49022 @Grab annotation support
5

Attachments

exception2.png   (79 KB)
Completion for Maven things in the attributes
Comments (30)
 
History
 
Linked Issues (0)
 
Antonel Ernest Pazargic
  Antonel Ernest Pazargic
08 Sep 2009 18:52
(11 months ago)
It is imposible (at least for me) to run groovy scripts annotated with @Grab, in current version (Idea 10666 buid Maia) .

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
Peter Gromov
  Peter Gromov
08 Sep 2009 19:04
(11 months ago)
Antonel,

Could you file a separate JIRA issue. How is the Groovy library in your module configured, which jars does it include?
Richard Rattigan
  Richard Rattigan
04 Feb 2010 19:00
(6 months ago)
I would expect @Grab dependencies to be downloaded and added to the project automatically. As far as I can tell, Grab annotations are ignore by JetGroovy (version 9.0). Having to add these dependencies manually makes using Grape rather pointless.
Marco Behler
  Marco Behler
10 Feb 2010 17:42
(6 months ago)
I'd also like to see support for this.
Benoît d'Oncieu
  Benoît d'Oncieu
25 Mar 2010 17:51
(5 months ago)
+1
Sean Brandt
  Sean Brandt
01 Apr 2010 00:27
(5 months ago)
This is actually not so much a feature request as actual breakage. @Grab and it's supporting annotations are all part of the groovy 1.7 language and need to be supported by the IDE. Having to have multiple configurations for classpath / dependencies in pure groovy projects isn't right.
Peter Gromov
  Peter Gromov
15 Apr 2010 20:03
(4 months ago)
To download the @Grab-defined dependencies automatically, you may try this plugin: http://plugins.intellij.net/plugin/?idea&id=4702 with the latest EAP. After you install it, you can put the caret onto @Grab annotation and press Alt+Enter to see the intention which should download the dependencies. It depends on your feedback when this feature will be available in the core IDEA.
Per Olesen
  Per Olesen
19 Apr 2010 23:25
(4 months ago)
The plugin doesn't work for me (see comment on plugin page).

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.
Taras Tielkes
  Taras Tielkes
19 Apr 2010 23:53
(4 months ago)
Per, are you running IDEA on Java 5? Perhaps the plugin is compiled with -target 1.6?
Per Olesen
  Per Olesen
20 Apr 2010 00:03
(4 months ago)
Nope. Running on 1.6.0_17.
Taras Tielkes
  Taras Tielkes
20 Apr 2010 00:42
(4 months ago)
Perhaps current project JDK is 1.5 then? :)
Per Olesen
  Per Olesen
20 Apr 2010 00:50
(4 months ago)
Yes the project jdk is 1.5. Does that affect the plugin?
Peter Gromov
  Peter Gromov
20 Apr 2010 06:19
(4 months ago)
Per, Taras: it does really affect the plugin, sorry. fixed
Per Olesen
  Per Olesen
20 Apr 2010 11:49
(4 months ago)
mkay, but know I get another exception. Again, see comment on plugin :-)
Taras Tielkes
  Taras Tielkes
21 Apr 2010 03:26
(4 months ago)
Per, posting the full stacktrace here (if available) would be useful.
In addition, what does your full classpath look like? What version of groovy are you using?
Per Olesen
  Per Olesen
21 Apr 2010 10:45
(4 months ago)
Hi Tara, I mailed Peter Gromov the stacktrace and info about the classpath. I am not sure if he is looking at it currently, do you know? :-) I could put the info here too, if you like?

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?
Taras Tielkes
  Taras Tielkes
21 Apr 2010 14:32
(4 months ago)
Hi Per,

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?
Per Olesen
  Per Olesen
21 Apr 2010 15:22
(4 months ago)
Hmm, good point. Only thing is, if we dont, code that uses classes from dependencies will be colored red as in error in idea. Currently, we add the dependencies to the pom.xml too, which is like adding them to the module.

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?
Peter Gromov
  Peter Gromov
21 Apr 2010 15:23
(4 months ago)
Taras, Per,
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.
Per Olesen
  Per Olesen
21 Apr 2010 15:27
(4 months ago)
Interesting
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?
Per Olesen
  Per Olesen
21 Apr 2010 15:35
(4 months ago)
Oooh, just saw you (Peter) sent a new version 3 hours ago. Tested it. Now getting another exception. Going to attach screenshot in a second.
Per Olesen
  Per Olesen
21 Apr 2010 15:36
(4 months ago)
Just attached exception2.png showing the problem
Peter Gromov
  Peter Gromov
21 Apr 2010 17:07
(4 months ago)
Do you have Ivy's ResolveReport class in your dependencies?
Per Olesen
  Per Olesen
21 Apr 2010 17:17
(4 months ago)
No, I didn't. But I tried adding this dependency:

<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?
Per Olesen
  Per Olesen
21 Apr 2010 17:18
(4 months ago)
BTW: Should ivy not be part of the plugin?
Peter Gromov
  Peter Gromov
21 Apr 2010 17:53
(4 months ago)
It may become a part of 9.0.3 or later, and it will certainly become part of IDEA 10. But until then it's available as a separate plugin.

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
Per Olesen
  Per Olesen
21 Apr 2010 18:16
(4 months ago)
:-) I wasn't running them from within IDEA, so that might have failed if I did. When I run them with groovy on the cmdline like this:

groovy FooBar.groovy

I guess groovy 1.7.2 includes ivy in its classpath.
Per Olesen
  Per Olesen
21 Apr 2010 18:17
(4 months ago)
I might not have the big picture, but if the plugin needs ivy to work, I would think it should include ivy!? ;)
Peter Gromov
  Peter Gromov
21 Apr 2010 18:39
(4 months ago)
It's Groovy that needs Ivy to work. It even includes Ivy, but only in the standard distribution which is not what you're using in IDEA. I was thinking about talking to Maven and getting Ivy from there. IDEA-54025 is about the same issue
Per Olesen
  Per Olesen
21 Apr 2010 18:42
(4 months ago)
Okay. Cool!