Java Reference
In-Depth Information
quires an import statement (or copy-and-paste reuse), plus some effort to make sure the
tasks are not tied to a particular project structure.
Again, the benefit here is that this is all completely portable. The Ant build should work
just as well on Mac OS X as it does on Windows or Linux. The downside is that this is a
trivial Hello World application and the build file is already over 35 lines long. Once you
add in the junit and junitreport tasks, to say nothing of customizing the classpath
withthird-party libraries, thesize ofthisfile will growquickly.Amoreextensive buildfile,
including the JUnit 4 libraries and a test case, can be found in the chapter source code.
Rather than do that here, however, let me show you how to introduce Groovy into this sys-
tem.
5.3. Making Ant Groovy
Ant is not as common in Java builds as it used to be, but switching build tools is a major
decision for most organizations and not to be undertaken lightly. If you're working with a
large installed base of Ant builds, then Groovy can still contribute.
Four approaches are available:
• Groovy scripting code can be added directly to an Ant build file.
• Groovy scripts and classes can be compiled and executed in Ant builds using spe-
cial Ant tasks for that purpose.
• The Groovy standard library contains a special class called
groovy.util.AntBuilder that can replace the XML build file with Groovy
scripting code that does the same thing.
• There's a Groovy DSL available, called Gant, which provides an alternative to
AntBuilder .
AntBuilder
Even if you don't use Ant, the AntBuilder class is worth knowing about because it's
embedded in other build tools, like Gant and Gradle.
Search WWH ::




Custom Search