Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant depends vs. antcall

When defining sequential build steps I use the depends attribute of the target element. I have recently seen an ant file, where the build sequence was defined by antcall elements inside the targets. To illustrate :

<target name="a" depends="b"> ...</target> 

vs

<target name="a"> <antcall target="b"/> ...</target> 

Is there a real difference between the two approaches? Is one of them preferable?

like image 318
kostja Avatar asked May 09 '11 12:05

kostja


People also ask

What does depends mean ant?

The depends attribute can be included in the target 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. <target name="one" depends="two, three">

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.


1 Answers

The biggest difference is that Ant will ensure that dependencies declared via depends are called at most once. For example:

<target name="a" />  <target name="b" depends="a" />  <target name="c" depends="a" />  <target name="d" depends="b, c" /> 

If I call target d, b and c are called. However, a is only called once (even though both b and c depends on it).

Now suppose we decide to use antcall instead of depends for target d:

<target name="d">    <antcall target="b" />    <antcall target="c" /> </target> 

Calling target d will now call targets b and c; however, target a will get called twice, once for b and then again for c.

In other words, antcall sidesteps the normal dependency rules that are the cornerstone of Ant.

I don't think antcall should be used as a substitute for normal Ant-like dependencies; that's what depends is for. So when would you use it? The antcall task does allow you to control what properties and references are defined (which is why a new Ant environment is created--and why it's so slow) so it can be used to create variants of the same thing; e.g., maybe two jars, one with and one without debug symbols.

Overusing antcall, however, creates slow, brittle, and hard to maintain build scripts. Think of it as the goto of Ant--it's evil. Most well-written build scripts simply don't need it except in unusual cases.

like image 142
Richard Steele Avatar answered Oct 13 '22 19:10

Richard Steele