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 https://svn.codehaus.org/plexus/trunk/plexus-sandbox/plexus-components/
plexus-compiler/plexus-compilers/plexus-compiler-groovyc/
(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:


            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerId>groovyc</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-groovyc</artifactId>
                        <version>1.5.1</version>
                    </dependency>
                </dependencies>
                <extensions>true</extensions>
            </plugin>



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...

5 Comments

  1. Erik Husby

    Grabbed the code via svn but when I try to build I get unresolved dependencies for cglib-nodep-2.1, xpp3-1.1.3.4-RC8_min. Failed to find then at http://repo1.maven.org/maven2 — 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? : http://mojo.codehaus.org/using-sandbox-plugins.html

    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!

Trackbacks

  1. Groovy, Maven, and GSpec Trouble « Can’t see nothing but the source code
  2. Groovin’ with Maven « Can’t see nothing but the source code

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 250 other followers