39

If I have three targets, one all, one compile and one jsps, how would I make all depend on the other two?

Would it be:

<target name="all" depends="compile,jsps">

...or would it be:

<target name="all" depends="compile","jsps">

Or maybe something even different?

I tried searching for example ant scripts to base it off of, but I couldn't find one with multiple depends.

Lii
  • 11,553
  • 8
  • 64
  • 88
corsiKa
  • 81,495
  • 25
  • 153
  • 204

4 Answers4

72

The former:

<target name="all" depends="compile,jsps">

This is documented in the Ant Manual.

Tomap
  • 610
  • 8
  • 22
Brett Kail
  • 33,593
  • 2
  • 85
  • 90
11

It's the top one.

Just use the echo tag if you want to quickly see for yourself

<target name="compile"><echo>compile</echo></target>

<target name="jsps"><echo>jsps</echo></target>

<target name="all" depends="compile,jsps"></target>

You can also look at the antcall tag if you want more flexibility on ordering tasks

laher
  • 8,860
  • 3
  • 29
  • 39
10
<target name="all" depends="compile,jsps">

This is documented in the Ant Manual.

animuson
  • 53,861
  • 28
  • 137
  • 147
Don Roby
  • 40,677
  • 6
  • 91
  • 113
5

An alternate way is to use antcall which is more flexible if you want to run the depending targets in parallel. Assuming compile and jsps can be run in parallel (i.e in any order), all target can be written as:

<target name="all" description="all target, parallel">
  <parallel threadCount="2">
    <antcall target="compile"/>
    <antcall target="jsps"/>
  </parallel>
</target>

Note that if targets can not be run in parallel, it is preferable to use the first flavor with depend attribute because antcalls are resolved only when executed and if the called target does not exists, the build will fail only at that point.

Phil
  • 390
  • 5
  • 5
  • Thanks a lot for your useful post! For some reason all the information about , and I found does not tell any word how to parallelize not standard Ant tasks, but *targets*. The answer is just I have to use ! I combined this approach with to avoid copy-pasting of for every list entry and it also worked. – Alexander Samoylov Apr 01 '21 at 14:08