|
|
A quick look at Groovy builds with Gant
|
|
|
| |
April 29th, 2008
|
I've been looking into Groovy lately, and I'm really impressed. The language is powerful but concise, the tool support and documentation seems good and getting better, and the community is growing. The problem is, in an enterprise environment, I have no idea where it actually fits in. I don't think it makes sense using it for any large-scale system, at least for now - weak typing scares me in team environments...and in general it's just too bleading edge. So what else?
Well...I recently read Groovy-powered automated builds with Gant, and I think the case here is strong. Groovy could make a lot of sense as a replacement or complement to Ant. After a few hours of playing around with Groovy, Gant, and AntBuilder, here's my humble assessment.
Advantages
- Full Ant API available, as well as hooks to Ivy and Maven.
- Readable, concise language. Much less typing than XML.
- Native support for conditional logic and looping constructs (i.e. no AntContrib, Jelly).
- Benefits of OO. Greater opportunities for code reuse, better modularity.
- Extension easier. Groovy code simpler to write than custom Ant tasks.
- Learning. Get to tell people you know Groovy! :)
Disadvantages
- Little documentation or tool support. Seems to be very bleeding edge.
- Learning curve. Groovy and Gant take time to learn. Must understand closures.
- Potential maintenance issues if leaving for less tech-savvy developers.
When to Use
- Complex builds that require non-standard functionality (i.e. Groovy is easier to write than custom Ant Tasks).
- Environments where people are open to using (and maintaining!) newer technologies.
When *not* to Use
- Large teams or when other people are going to maintain your build code (and will curse you if they don't know or want to know Groovy).
- Environments that are apprehensive about new technologies.
- Deadline pressure or risky projects - just use Ant!
Resources
Hello World - Ant vs. Gant
// Ant
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="E" default="compile" basedir="." >
<target name="compile" depends="init">
<mkdir dir="classes/" />
<javac srcdir="src/" destdir="classes/">
<classpath>
<pathelement location="lib/log4j.jar"/>
</classpath>
</javac>
<copy todir="classes/" file="src/log4j.properties" />
</target>
<target name="jar" depends="init, compile" >
<jar jarfile="lib/e.jar" basedir="classes/" includes="**/**" />
</target>
<target name="clean" depends="init" >
<delete failonerror="true" dir="classes/"/>
</target>
</project>
// Gant
target (clean: "Clean") {
Ant.delete(failonerror: false, dir: "classes/")
}
target (compile: "Compile") {
Ant.mkdir(dir: "classes/")
def javaCompileClasspath = Ant.path {
pathelement(location: "lib/log4j.jar")
}
Ant.javac(destdir: "classes/", srcdir: "src/",
classpath: javaCompileClasspath)
Ant.copy (todir: "classes/",
file: "src/log4j.properties" )
}
target (jar: "Jar") {
depends(clean, compile);
Ant.jar(jarfile: "lib/e.jar",
basedir: "classes/", includes: "**/**")
}
setDefaultTarget(compile)
Post a Comment
View Comments (18)
|
|