Saturday, August 7, 2010

Groovy-PDE Redux

Up until recently, doing any PDE work with Groovy has been a bit of a kludge. First, you had to create a customCallBack.xml script. Inside this script you had to call out to a special groovy.jdtcompile ant task, using a magic set of classpath references. When this approach worked, it did so by first compiling your Java code (with errors of course since your groovy code is not touched), and then re-compiling all your code using the joint compiler provided by Groovy-Eclipse.

Not so pretty. It works for Groovy-Eclipse, but that is only because I know exactly what its limitations are and how to work around them.

A short while ago, I wrote about how we re-implemented PDE build for projects that use the AspectJ compiler. I've recently done the same for plugin projects that use Groovy.

Here's how it works:

  1. Install the latest dev snapshot of Groovy-Eclipse for Helios (you can write plugins that target Galileo (Eclipse 3.5), but you must use the Helios PDE builder to create the plugins).
  2. For each of your plugin projects, add the following to your file:
    sourceFileExtensions=*.java, *.groovy
    compilerAdapter.useLog=true  # this ensures that exceptions are logged to the proper log file.
  3. Now you can run your PDE export (either headless or from within a running Eclipse using one of the Export wizards).

The only caveat is that each plugin project must contain at least one .java file or else the PDE builder will ignore that plugin. The problem is described in Bug 318951. Before this can be addressed, I need a patch committed to the javac task, described here: Apache Bug 48829 (please vote the bug up if you want to see this fixed!).

With that, creating Groovy-based Eclipse plugins now requires much, much less black magic.


  1. Thanks for your post, exactly what I was looking for.
    Can you perhaps lead me to some source where such Groovy-specific Eclipse additions are described?

  2. lero, what exactly are you looking for?

  3. Nevermind, when I wrote the comment I wasn't aware of how the properties in the file were used. Turned out all I was looking for was the Eclipse help ^^

  4. Thanks Andrew, you made my day. I spent 2 days of developing plugin in groovy which worked like a darling from Eclipse, but didn't work on export - the groovy files were not compiled and were present in plugin jar as .groovy.

    Adding to the as you mentioned helped!