Groovy 1.6 Final Released

nvisia is an award-winning software development partner driving competitive edge for clients.

The Groovy team has published their final release of Groovy 1.6.  I’ve followed the release candidates for a while, and have been especially interested in the Grape module and dependency system that is part of this release.  It was a bit buggy in the release candidates but it seems to be working now.  This feature solves one of the biggest hassles with using Groovy scripts….adding dependencies to the classpath.

For example, if you wanted to use some of the utilities from the Jakarta commons-lang project in your script, you’d have to download the jar and either put it in your environment classpath or add it to the GROOVY_HOME/lib directory.  Which was a minor nuisance, but it really became a much larger hassle if you wanted to use that script on another machine or give it to someone, since they also had to download and setup the dependencies or you had to send them in a huge zip file with your script.  Well, no more.  Now, if you want to use StringUtils from commons-lang, it’s as easy as this:

#!/usr/bin/env groovy
import org.apache.commons.lang.StringUtils
@Grab(group='commons-lang', module='commons-lang', version='2.4')
def useStringUtils() {
    println StringUtils.leftPad("leftPad me into a 75 char string", 75, " ")
}
useStringUtils()

You can save this into a file and run it from the command line and it will automatically take care of downloading the commons-lang jar in the background.

What this means is that you can now use Groovy as a cross platform scripting language just as easily as perl and other alternatives.  In fact, the transparent downloading of dependencies and large number of Java frameworks in existence arguably make it better than those other scripting alternatives.

Also as mentioned in the announcement, other highlights of the 1.6 release include performance improvements, multiple assignments (i.e. you have functions that return multiple values and assign them to multiple variables, e.g. def (x, y) = getCoords()), AST transformations, swing builder improvements, integration of the JMX builder, built in JSR-223 scripting engine, and metaprogramming improvements.

Using history as a guide, this release also probably means that Grails 1.1, which is in beta3 at this point, is getting close to being officially released.

While Grails hasn’t gained as much momentum as I had hoped, it definitely is gaining interest.  And the purchase of G2one by SpringSource certainly hasn’t hurt.  For example, see their recent case study describing how Wired.com built the product reviews portion of their site with Grails.

It will be interesting to see if all of this activity finally pushes Groovy into the top 20 of the TIOBE index by the end of this year.

Edit: InfoQ has a good expanded overview of what’s new in Groovy 1.6 here.

Related Articles