Ant depends on antcall

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

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

against

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

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

+45
java build-process build-automation ant
May 9 '11 at 12:34
source share
5 answers

The main difference between the two approaches is that the goals in depends always fulfilled, and the goals in antcall are only fulfilled if they contain the target.

Explanation Example:

 <target name="a" depends="b" if="some.flag"> </target> 

Here b will always be executed, and a will be executed only if some.flag defined.

 <target name="a" if="some.flag"> <antcall target="b" /> </target> 

Here b will be executed only if a , i.e. if some.flag defined.

+52
May 9 '11 at
source share

The biggest difference is that Ant ensures that dependencies declared through depends are called no more than 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 called. However, a is called only once (although both b and c depend on it).

Now suppose we decide to use antcall instead of a dependency 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 be called twice, once for b , and then again for c .

In other words, antcall circumvents normal dependency rules, which are the cornerstone of Ant.

I do not think that antcall should be used as a replacement for normal Ant dependencies; what for depends . So when do you use it? The antcall task allows you to control which properties and links are defined (which is why a new Ant environment is created - and why it is so slow), so it can be used to create variations of the same thing; for example, there may be two banks, one with one and one without debugging symbols.

Using antcall , however, creates slow, fragile, and tough build scripts. Think of it as goto of Ant - this is evil. Most well-written build scripts are simply not needed, except in unusual cases.

+77
May 09 '11 at 17:47
source share

Antcall is relatively rarely used because:

The called target is launched in a new project; keep in mind that this means properties, links, etc., so-called goals set will not be saved to the calling project.

In other words, antcall is a completely new Ant isolated process.

+14
May 9 '11 at 12:38
source share

antcall is GOTO ant. This is terrible. This is a great way to make rats a nest of overwhelming jerking. Next to ant -contrib, this is the best way to feel the overly complex process of storing an ant file. (even a good antfile is rude)

If your parameter is set correctly, you must successfully complete any goal to this point, unlike the antcall template.

Another reason that no one has touched is vizant, the ability to generate a graph of your target dependencies is pretty sweet if it's a complex build. If you use antcall, you are screwed.

I want @ Vladimir Dmitrievich to be right that antcall is rarely used - I have been to many stores where this is the norm.

+7
Feb 09 '12 at 20:01
source share
  <target name="a" depends="b"> ...</target> 

This means that before executing any statement or any tag from target a, ANT ensures that target b is successfully executed

And you can call any target with antcall after some statements or tags are executed from calling the target.

0
May 09 '11 at 13:35
source share



All Articles