Groovy Eclipse JUnit issue

Recently I have tried to run some junits from eclipse that where depending on groovy classes and the eclipse console had shown some odd error cause of which was something like:

...

Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.GroovyCategorySupport.getCategoryNameUsage(Ljava/lang/String;)Ljava/util/concurrent/atomic/AtomicInteger;
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:672)
    at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
    at groovy.lang.Script.invokeMethod(Script.java:78)
    at

...

which was very strange because running the same JUnit test from console did not give any errors.

 

After doing some invesigation about this issue I have reached the cause of the problem: collision in groovy versions.

The problem was the cause of sequesnce of events:

1. our project required groovy and we used version 1.5.7

2. in order to work with groovy in eclispe we have installed groovy plugin

3. we found some odd behaviour that was fixed in version 1.6.0 and upgraded the groovy dependency

4. we got the above error.

Although this sequence may seem easy to understand but when you are running all tests from console and after a month or so need to revise your JUnit - this just does not sound as easy.

 

So we got the issue - what can we do about it?

I have searched the Groovy official site and have not found any eclipse plugin updates. The update site in eclipse also told me that my groovy plugin is up to date. There was an option of checking out code from their repository but I was not keen on doing that at the time - nor do I now...

In order to solve the issue we need to trick the plugin into using the 1.6 version, so what we need to do is to update the groovy runtime jar within our plugin (note that this is only if you have a 1.6 + version of groovy in your dependency and 1.5 plugin).

1. go to ${ECLIPSE_PLUGIN}/org.codehaus.groovy_1.5.7.20081120_2330/

2. in there you should see groovy-all-1.5.7.jar and source jar's for it.

3. the trick is that you cannot just drop your 1.6.0 jar there - you need to overwrite it, so that the name of jar stays the same.

4. go back to eclipse and try to run your test

5. Voilà...

NOTE: sometimes it is necessary to switch the 1.5.7 runtime back when some other issues appear. But the rule of thumb is always run your tests from console, just to make sure!

Ahh, another eclipse lesson learned - isn't it fun? come on you'd be bored if eclipse would just work... (WARNING: this joke is not recommended for people whose workspace has just gone nuts, give them some time to take it in - then tell)

 

Enjoy :-)

 

This page was last updated on: 03/08/2009 07:27