Today I got closer than ever to building the Groovyc plugin from the Codehaus Mojo sandbox. I started by looking at the old source that I had downloaded. I then started creating idea modules out of each maven project with the Idea plugin for Maven2. (That is a plugin that runs in Maven2 not a plugin that installs in Idea.) I fumbled around a bit then figured out what had me so hung up last time I tried building. The Groovyc plugin had a dependency on a plexus-compiler-groovyc jar that Maven couldn’t find anywhere. Getting to the point I was able to successfully build and install the Javalike tools plugin from the Codehaus Mojo sandbox. and finally install the Groovyc plugin! Then something really funny jumped out at me. Just see if you follow this…
I’m looking at the source for the Groovyc M2 plugin and it uses AntBuilder to do the compiles. Cool. Then I’m thinking, “Hey this plugin is written in Groovy! That’s pretty slick!” I don’t see the need for the stoopid plexus-compiler-groovyc jar that dumb Maven can’t find because it uses Antbuilder and it doesn’t try to extend Plexus. I comment out that idiotic dependency and viola! It builds with no problem! I install and try to use it on an example dummy Groovy Maven2 project that I generate via the Java archetype plugin. I keep getting ClassNotFoundExceptions from Maven as it tries to load/run the Groovyc plugin. I look in the target output folder for the Groovyc plugin project and see that there are no class files in it! D’oh! I think a little harder and figure out that there’s no way for Maven to compile the source for the project without, you guessed right… a Groovy compiler! “Ooooh! That’s why we need the dumb plexus-compiler-groovyc jar. Looking deeper in the docs I see that it’s supposed to be in some plexus sandbox repo or something. A little Googling and I find it. I run into all kinds of problems getting it because it’s just source on a svn repo and I’m not seeing how to check it out.
Long story shortened…
I finally get the plexus-compiler-groovyc.jar installed and get a real groovyc plugin built and installed. I’m too excited to fire it at my example Groovy/Maven2 project when I start getting
java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildLogger errors. Ok, I got all this far and guess what? Think about it. Do you see anything wrong with this picture? I’ll spell it out.
Here’s the problem:
- I put in all that effort trying to build a groovy compiler plugin to compile groovy projects.
- The main thing that always stopped me from being able to build and install the plugin was a compiler to compile the project.
- The plugin project was a Maven2 project so I needed, found, built, and installed a Maven2 Groovy Compiler so I could build a Maven2 compiler plugin which is still broken!
It seems like the sandbox plugin was an academic excercise or a means of testing the groovy javalike maven tools plugin which would allow you to write plugins in groovy. The whole time I struggled for a compiler my answer was right in front of me. I have a Maven2 groovy compiler that I have succesfully used to build a Maven2 project. I completely missed that fact in my dilligence to build the Antbuilder based plugin that still doesn’t work. So in the end there’s good news and there’s bad news. The bad news is how I still can’t get the compiler plugin to work. The better news is that I’ve found and built the source for the Plexus compiler extension for Maven2 that i wanted all along. I’m going to try to squeeze some more time in and play with everything some more before I post the details on how to best build your Maven2 Groovy projects. I’m still not certain which way is best to go, the AntBuilder based plugin or the Plexus compiler extension. Either way is far better than my ealier solution of embedding Ant code in your M2 pom. Get at me if ya’ feelin me…
(The author does not expect to be physically felt or touched by any readers. Instead the idea is for readers to “get at” or leave comments for the author if they are “feelin'” or in agreement with the above text. Apologies to those who got lost in the context.)