Thursday, January 10, 2008

Building Grails Applications With Hudson

We're doing some retooling of our development environment. One of the changes we are making is swtiching from CruiseControl to Hudson. These tools provide automated builds for all of our projects and we found that Hudson was just a bit simpler to set up and manage. Our Ant and Maven based projects were a breeze to set up under Hudson but our Grails apps gave us a bit more trouble. Most of my issues stemmed from trying to use the generated Ant build.xml in the grails application. There were a lot of tricks I had to do with environments or in editing the build.xml that I did not like. Each fix seemed to make the project less portable. So I switched from using Ant to just using Hudson's "Execute Shell" build option and everything worked great. Basically, all the environment variable setup that needed to bet set for the build under Hudson (JAVA_HOME, GRAILS_HOME) could be done in the Hudson configuration for the build and not in the project files in Subversion. My script ended up looking like: JAVA_HOME=/usr/jdk/latest; export JAVA_HOME GRAILS_HOME=/opt/grails; export GRAILS_HOME cd trunk $GRAILS_HOME/bin/grails upgrade <<FOO y FOO $GRAILS_HOME/bin/grails test $GRAILS_HOME/bin/grails war The script executes immediately after the project is checked out in the Hudson workspace. The odd bit of shell code that performs the Grails "upgrade" is necessary when checking out for the first time from Subversion. This is explained on the Grails site. The "here doc" is required because the Grails upgrade command needs some interactive input from the user. Normally that's not a problem but when using an automated build you need to push the answer into the command. This setup works perfectly, gives me the control I need to perform the build, and keeps my project artifacts free from environmental specificity. If anyone knows a better way I'd love to hear about it.

Technorati Tags: , , ,


Blogger jlorenzen said...

Excellent post!
We also use hudson and I have been playing around with grails and have often wondered how to merge the two together.
A couple of other options would be to use the Maven Tools for Grails (

Or you could create your own pom.xml and map it to the build.xml (which is what I assume MTG does).

However I don't think it gets much simpler than your solution. Our builds are a bit more complicated though, but I would definitely start with your script.

You might consider writing a grails plugin for hudson. From what I have read its pretty simple and hudson is very extendable. See this site for more information:

Have a look at my site. I regularly blog about hudson, grails, and groovy.

12:27 PM  
Blogger Stephen said...

Worked great, thanks.

11:28 AM  
Blogger William Pietri said...

Very helpful. Thanks!

For what it's worth, Hudson already sets JAVA_HOME, at least under 1.310, so you can leave that out. Also, the Unix "yes" command lets you do this:

yes | $GRAILS_HOME/bin/grails upgrade

4:43 PM  
Blogger Bernd Donath said...

Using Hudson ver. 1.336 I solved this using two subsequent build actions. The first one is a Shell action running the grails 'upgrade':

cd "$WORKSPACE/trunk"
yes|grails upgrade

the second one is an Ant action which actually creates the WAR:

ant clean war

12:31 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home