A while ago I posted my interest in using Groovy instead of ant for scripting my build file. I spent the last couple of days working on this. I thought people might be interested in my results.
Summarizing my previous post, I don't like ant because I don't like XML. I think that's about all the important points...
I have two comparable build files, though they do not perform identically. Here's a comparison of them based on size:
dusty:~ $ wc build.groovy build.xml 138 319 3630 build.groovy 158 584 6262 build.xml
The xml build file has 20 more lines, and almost twice as many words and characters as the groovy build file. In other words, a groovy build file is less typing, although you would tend to press the enter key about an equal number of times.
Here are the two files, for visual comparison (NOTE: I removed some targets from the xml file that haven't been implemented in the groovy script yet, but they still aren't identical): http://www.buchuki.com/misc/build.xml http://www.buchuki.com/misc/build.groovy
Unfortunately, firefox won't syntax-highlight the groovy file. Aside from that, which one do people think is easier to read? I personally prefer the groovy markup, but maybe I'm strange.
The main observation I found coding the groovy file is that its much easier to reduce duplication of code in a groovy script (just toss it in a method) than in an ant file (put it in a target and depend on it, sometimes conditionally). Also, its easier to group properties together into maps and having generic code manipulate them. This reduces both the number of total properties and the total amount of code.
Most articles I've read have been anti-groovy scripting, and I doubt this would become a standard either within the Java community (ie: where ant currently dominates) or across all projects that need build management. I just find it interesting, and I must confess that I prefer it.
Hmmm, I think the groovy one is easier to read (for me), but I can see where someone can look at the xml file and deduce things easier [ for instance... func(something: anotherthing) is confusing to me... I'm not sure which is the type and which is the variable w/o looking inside the function]
Oh, and with the syntax highlighting... try this: vim build.groovy :TOhtml :wq
bam! I love that - it outputs the vim syntax highlighting scheme as html...
On Wednesday 13 Apr 2005 20:14, Dusty Phillips wrote:
Most articles I've read have been anti-groovy scripting, and I doubt this would become a standard either within the Java community (ie: where ant currently dominates) or across all projects that need build management.
I just find it interesting, and I must confess that I prefer it.
Well, that's what it's all about is it?! :)
You're right, Ant has become the de facto standard in Java projects. I never try writing one from hand because it's too much faff (although if I *actually* learned the syntax, then I may fare better!!). I just load up Eclipse, import the project from the file system and then it's possible to export Eclipse's generated Ant file. Sure, it's not customised, but it gives everything I need. Netbeans does a similar thing.
To be fair, I've seen more complex ant files than the example you posted! I was impressed by the Groovy approach you've taken. If your goal is to simply type less to create a build script, then you can consider this approach a success. However, I wouldn't say it's any easier than the Ant approach.