Groovy Maven

I meant to post the details of the Groovy integration for Maven2 but, you see there was this gang of ninjas, right? They were like, “Prepare to defend yourself!” I was without nunchucks so I did my best to fend off the would be assasins. I found myself tied up in some dirty basement with a wood floor and inadequate lighting. Barely concious, I wriggled my way out of my bondage only to find the basement door was locked. I’m not sure what the attackers had in mind (they probably wanted the secret plans to my XML based warships or something) but I had to think fast. With a broken rubber band, a half stick of chewing gum and a 1976 bicentennial penny I was able to…

Are you buying any of this?? Because it’s true!! I can show you the war scars on my belly. Anyway, more to the point of Groovy Maven integration. I haven’t had time to play with my findings due to my bouts with ninjas and all so I’ll share what I have so far.

Plexus Groovyc
The most important piece of the puzzle is an enhancement to the Plexus compiler to support Groovy compilation. Once we have that then we can easily compile Groovy source without extra Ant scripting and such. I found such a compiler here. To get all of its compiling goodness on your spinning magnetic hard drive platters alls ya’ haff tuh do is (don’t you just hate it when some egg head says “alls yuh haff tuh do is….”?) install a subversion command line client and run this command: svn co
(command is wrapped for formatting quality) in a conveneint directory. It will pull down all of the source code and place it in a folder called plexus-compiler-groovyc. walk into that folder (I don’t mean physically walk into it, rather issue a change directory “cd” command to get there) and install the maven project therin. If you’re still new to Maven2 then the process for doing that is mvn install. If you get a build failure then it’s not my fault. Yer on your own buddy! (However if you post a comment explaning your particular situation I’d be inclined to assist.) After the the project is installed you should be able to use the following snip in any Groovy Maven2 project:


Javalike Maven Plugin Tools
Now nothing could be more cool than getting Maven to compile Groovy code right? Wrong! What if I told you to go write a Maven plugin? "Aww man! I ain't tryin' ta' hear dat! I'd have to use stoopid Java syntax or clumsy Ant!", you say. Wrong! You can write a plugin today using pure groovy source. And guess what else? If you order now... err write it now... we'll have Maven dig into your Groovy source to pull out the annotations just the same way it would for Java source! "No way!", you say. "All the way!", we respond. There's a little known gem in the Mojo sandbox called Javalike Maven Plugin Tools that does the magic. Alls yuh haff tuh do is download the Maven2 sandbox (the whole sandbox including the sand), drill into the groovy-maven-tools folder (using your preferred power tool or command line console) and find the project. run the ol' "mvn install" command from that folder and viola! You can find detailed instructions for using and installing Mojo Sandbox plugins here on their site. (You really don't need the sand with the sandbox.)

That's cool for now. I'ma holla at'cha while you drop it like it's hot...


Add yours →

  1. Grabbed the code via svn but when I try to build I get unresolved dependencies for cglib-nodep-2.1, xpp3- Failed to find then at — because the names have changed. I am using Maven 2.0.4. Do I need to grab the latest snapshot build?

  2. It’s been a while since I did that myself. Did you add the snapshot repository to your maven environment as detailed here? :

    That’s kind of important as it allows the parent stuff to resolve. I grabbed the source from SVN about 4-6 months before writing the above post so I’m not exactly sure what names changed or where. If you tell me which project you’re trying to build I’ll try it from here and tell you what the dependencies should be. When in doubt, don’t be afraid to change the dependencies to point to the latest and greatest. I adjusted the Groovy stuff to point to JSR-06 and it built just fine. I think that actually fixed some earlier build issues where it was pointing to a bad version JSR-04 or JSR-03 or something like that.

  3. Great post, thanks for the info!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 262 other followers