Printing output in Grails 2.0 ant scripts

When developing plugins, in my case the Grails Fitnesse plugin, it’s sometimes handy to produce output to the user. In my case, I had a use case to give the user some information that Fitnesse had started up succesfully, and wanted to indicate the location Fitnesse was running on.

In previous versions of Grails (1.3.x), you could do ant ant.echo. However, as described in the Grails 2.0 release notes, the ant.echo doesn’t work anymore, and you’ll have to use ‘alternative mechanisms for output’.

Well, Spring Security Core had this already figured out. Just send a StatusUpdate event, which will be printed to the console automatically.

target('default': 'Starts Fitnesse Server') {
    printMessage "hello world!"

printMessage = { String message -> event('StatusUpdate', [message]) }
errorMessage = { String message -> event('StatusError', [message]) }

This be handy in the future for other plugin developers.


  1. I didn’t know that you could do it like that. I have been using a different approach which is to use the methods provided by grailsConsole, e.g.:
    `grailsConsole.addStatus “message”`
    `grailsConsole.updateState “message”`

    • Hi Matt,
      Thanks for the reply. You are right, I actually only discovered that today while checking out _GrailsTest.groovy. I’ll update the code!
      Thanks, Erik

  2. grailsConsole is new for 2.0, so if you’re targeting 2.0+ you can use that, but using events works with all versions of Grails.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>