Apache Ant/Depends

The  attribute can be included in the   tag to specify that this target requires another target to be executed prior to being executed itself. Multiple targets can be specified and separated with commas.

Here, target "one" will not be executed until the targets named "two" and "three" are, first.

Example of using the attribute
Here is an example of a build file that executes three targets in order, first, middle and last. Note that the order the targets appear in the build file is unimportant:

 Running One  Running Two  Running Three

Sample Output: Buildfile: build.xml one: [echo] Running One two: [echo] Running Two three: [echo] Running Three BUILD SUCCESSFUL Total time: 0 seconds

Redundant dependency
Ant keeps track of what targets have already run and will skip over targets that have not changed since they were run elsewhere in the file, for example:

 Running One  Running Two  Running Three

will produce the same output as above - the target "one" will not be executed twice, even though both "two" and "three" targets are run and each specifies a dependency on one.

Circular dependency
Similarly, ant guards against circular dependencies - one target depending on another which, directly or indirectly, depends on the first. So the build file:

  Running One  Running Two

Will yield an error:

Buildfile: build.xml BUILD FAILED Circular dependency: one <- two <- one Total time: 1 second

Next Chapter, Next Cookbook Chapter