A New Gradle Grails Plugin

My team wanted to use Gradle to build our Grails project.  We had some trouble with version compatibility problems between Grails and the Grails build plugin, though.  Instead of using the plugin, we tried writing some code that called the ‘grails’ command directly, but that caused problems with the CI server because it required that the correct version of Grails be preinstalled on all build servers and exist in a known location.  I decided to try my hand at writing a simpler Grails build plugin and this is what I came up with.  It doesn’t require Grails to be pre-installed on the machine and, since it just executes the ‘grails’ command, it works with any version.

Fork it!  Or just use it 🙂

Gradle Grails Wrapper

Posted in Gradle, Groovy at April 6th, 2012. 5 Comments.

A Yammer App Using Gaelyk for Google App Engine

I recently attended a presentation by Tim Berglund about Gaelyk at Uberconf.  The technology of Gaelyk is pretty straightforward and doesn’t need much of an introduction, especially with the excellent tutorial available on its web site.  Watching the presentation, I was struck by how little there is to Gaelyk and wondered why I was there.  Sitting in a room of developers and coding a working, useful application in just over an hour, though, reminded me about how much fun web programming can be.  Many of us have become so accustomed to frameworks like Struts, WebMVC, GWT and Grails that we’ve forgotten the simpler times, when you could slap together some Servlets and JSPs and have fun putting together a small, useful app.  Gaelyk brings back those simpler times and makes them even more enjoyable by adding the conveniences of Groovy and App Engine.

I picked an app that I wanted to code, something that would tell Yammer users what their companies are talking about.  It’s available for anyone to use at http://whatyammer.appspot.com.

Data access

Want to save a record to the database?  Forget about messing around with bean and data access classes, database connections and ORM.  No need to create tables.  You’re coding for fun!

def user = new Entity('user')
user.email = params.email
user.name = params.name
user.phone = params.phone

That’s all.  To get that record back out

datastore.execute {
  select single from user
  where email == params.email

Forwarding objects to a view

Gaelyk views are coded in gtpl files, which are much like JSPs. The controller, echo.groovy

request.users = datastore.execute { select all from user where email == params.email }
forward 'showusers.gtpl'
The view, showusers.gtpl
Adventure Time with <%= (request.users*.name).join(' and ') %>
That prints the names of all users, with the word and between each one.  That is just a small taste of what Gaelyk makes available.  So simple!  So much fun!  Single-command deployment!  Google will host 10 apps for free, so there isn’t any reason not to try it out.  Just note that before you deploy, you have to visit http://appengine.google.com and register your new app or Google will give you a very unhelpful error message.

Posted in Groovy at August 19th, 2011. No Comments.

Functional Test and Integration Test Targets in Gradle

* Update February 13th, 2012: Thanks to Ben Ripkens for updates to match the new Gradle API.

While searching online, I found many suggestions for how to add a new test target to a Gradle script. Most of them were wrong and others didn’t properly separate the integration test target from standard targets. After not finding a solution, I came up with one on my own.

This example sets up integration tests for Groovy .

Create a source set

This will separate the integration test code from other code, allowing it to be built separately.

  • The classpath in the example gives integration tests access to all application and test classes
  • The source location will be src/integrationTest/groovy
sourceSets {
  integrationTest {
    compileClasspath = sourceSets.main.output + configurations.testRuntime
    runtimeClasspath = output + sourceSets.main.output + configurations.testRuntime
    groovy {
      srcDir 'src/integrationTest/groovy'

Add the target


task integrationTest(type: Test) {
  testClassesDir = sourceSets.integrationTest.output.classesDir
  classpath = sourceSets.integrationTest.runtimeClasspath


Posted in Java at January 11th, 2011. 3 Comments.