Handling Dependencies
The javac task does a
good job of handling dependencies, but it's limited because it only
compiles .java files if the corresponding
.class file is older or does not exist. It doesn't
check the files those .java files might depend on,
such as parent or imported classes. The depend task, however, lets you perform this
kind of dependency checking.
When this task finds out-of-date classes, it removes the .class files of any other classes that depend on them. To determine dependencies, this task analyzes the classes in all files passed to it, using the class references encoded into .class files by the compiler. (It does not parse or read source code.)
You typically use the depend
task before compiling. Here's an example that uses depend before calling javac:
<?xml version="1.0" ?>
<project default="main">
<property name="message" value="Building..." />
<property name="src" location="source" />
<property name="output" location="bin" />
<target name="main" depends="init, compile, compress">
<echo>
${message}
</echo>
</target>
<target name="init">
<mkdir dir="${output}" />
</target>
<target name="compile">
<depend srcdir="${src}"
destdir="${output}"
closure="yes"/>
<javac srcdir="${src}" destdir="${output}" />
</target>
<target name="compress">
<jar destfile="${output}/Project.jar" basedir="${output}"
includes="*.class" />
</target>
</project>The attributes of this task appear in Table 10-4.
Tip
If you don't want to have to check dependencies, you can wipe all the directories ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access