Suppose I have a simple build script with the following 4 targets:
build
- Compile's the project's code, depends oninit
init
- Sets up the build environment, depends on nothingclean
- Deletes all files generated bybuild
andinit
, depends on nothingall
- Simply cleans and then builds, depends onclean
andbuild
<project> <target name="build" depends="init"> <echo>Building the project</echo> </target> <target name="init"> <echo>Setting up the build environment</echo> </target> <target name="clean"> <echo>Deleting all generated files</echo> </target> <target name="all" depends="build,clean"> <echo>Full build complete!</echo> </target> </project>
The problem here is that the order of init
and clean
is ambiguous in Ant. If clean
is called, it needs to run before all other targets, including init
. However, init
cannot have depends="clean"
because we don't always want to run clean
.
I realize that reversing the order of build
and clean
in the all
target's dependencies (i.e. depends="clean,build"
) would technically get them to run in that order, however I don't consider this to be a satisfactory solution. Ant will still consider these targets to be siblings on the dependency tree, and will not actually enforce this order at all.
Another "solution" of course is to just hard code the ordering by using sequential <antcall/>
tasks. This might be what I have to eventually fall back on, but it's something I'm trying to avoid (for multiple reasons that probably aren't worth expanding on).
Also, I'm aware that Gradle has exactly this feature built in (believe me, I'm jealous of it), but at this point my company's project is deeply entrenched in Ant, so switching really isn't an option.
EDIT - To give a better idea of the sort of thing I'm looking for, here's an example using features that I wish Ant had:
<condition property="init.depends.list" value="clean" else="">
<contains string="${ant.project.call-graph}" substring="clean" />
</condition>
<target name="clean" />
<target name="init" depends="${init.depends.list}" />
After reading the manual page on Ant's bindtargets task, I'm starting to think Ant's target dependency list is immutable as part of its core design philosophy, so there might actually be no good answer to this question.