Download O`Reilly - Ant The Definitive Guide
Transcript
Ant: The Definitive Guide
Cascading Buildfiles
Cascading buildfiles can change the rules of property immutability and scope.
Developers sometimes use cascading buildfiles in large projects with many
subprojects, and each subproject has its own buildfile. A master buildfile at the root
of the project executes one or more of the subproject buildfiles to build parts of
the project or the whole thing. Developers wanting to build individual subprojects
run the buildfile in that subproject's directory and can effectively ignore the other
subprojects in their day to day work (hence the reason for the design). A public
example of such a project using cascading buildfiles is Jakarta's taglibs. In
Appendix B, we provide a section on writing cascading buildfiles, as well as tips on
how to manage the problems that the immutability (and possible mutability) of
properties may present.
3.4.3 Targets
When you run ant with no arguments, Ant reads the <project> element and uses the
default attribute to get the name of the first target to execute. In our example, that target is
called all. The all target in turn has dependencies on the bot and module targets, meaning
that Ant executes these targets before running anything inside of all (let's ignore, for the
moment, that the all target contains no elements); and these targets must complete
successfully in order for Ant to start processing all. Since there are no elements in our all
target, the success of bot and module targets equates to the success of the all target.
3.4.3.1 The bot target
Since it is the first dependency in the list for the all target, the bot target runs first. The
purpose of the bot target is to compile the application and then package it up into a JAR file.
The bot target also has a dependency: the prepare target. The prepare target creates the
temporary build directories needed by the compilation steps. The mkdir task it uses is usually
successful, even if the directories mkdir is trying to create already exist. The mkdir task fails
only if the I/O system throws an exception because of file permissions, space limitations, or
some hardware or operating system error. In addition to creating directories, the prepare
target also timestamps the build using the tstamp task. The tstamp task has no attributes and
outputs nothing to the console or log. Instead, it sets properties that can be used later,
primarily in echo tasks, but also in any other tasks requiring the date and time. See Chapter 7
for details on the tstamp task.
The javac task compiles the Java source code. Let us take a close look at the javac task, as
it's defined in the bot target:
<javac destdir="${build.classes}"
debug="${debug.flag}"
deprecation="on">
<src path="${src.dir}"/>
<exclude name="irssibot/modules/**"/>
<classpath refid="classpath"/>
</javac>
There are three required settings for every javac task:
49