In the past I’ve used both ANT and Groovy. but independently. Ant for building J2EE EAR files for a large website, and Groovy as a shell scripting language for rather mundane admin-like functions on a Linux machine. Recently I used them together to implement another J2EE EAR file building process that is also somewhat user friendly for a non-ANT-or-Linux-familiar crowd.
At this point in time, what ANT is bringing to our table is just java classes that know how to call command like processes (like SVN) and know how to do standard things (like build a .war and/or .ear file.) And what Groovy is bringing to the table is a nicer way to invoke those classes, a la it’s AntBuilder class.
First off, the result is waaaay more readable. This is partially because Groovy’s syntax (while not exactly Java) is pretty readable for me as a Java developer who’s done a little Perl/shell scripting in the past. But is mostly due to the fact that you don’t have to write semi-complex code in XML. If you’ve ever had to wrap your head around someone else’s non-trivial build.xml file, you know what I mean.
Secondly you can easily implement conditionals/loops/user input. This is something that was sorely missing from plain ANT. An example of where this is handy for us is how we determine and retrieve which 3rd party jars we need to have on the classpath when compiling our Java code (in other words where I’d use Maven if I had a year to get it setup and working.)
The one unintuitive bit in all of this was that when I added the Ant-SVN tasks to the classpath I had to add them to Groovy’s classpath. That don’t make no sense. But also wasn’t too hard to deal with.
You can see the script here.
Posted by Erik
All Posts