To conditionally execute a step in Ant one has to resort to setting up a
target structure like this:
:
<target name="predicate">
<condition property="condition-satisfied">
<available .../>
:
</condition>
</target>
<target name="conditional-step" if="condition-satisfied">
<!-- conditional tasks here -->
:
:
</target>
<target name="conditional" depends="predicate, conditional-step"/>
<target name="main" depends="conditional">
:
:
</target>
:
This is because of several reasons:
* The ant tasks do not have something like *if* attribute.
* One cannot get away with only two targets instead of three because
the dependencies are executed before the dependent. Using the
above example it is not possible to do what target predicate does
in the main target and avoid using the predicate target.
* Ensure order of execution
However, I tried a solution making use of antcall task and it worked. It
works as follows:
:
<target name="conditional-step" if="condition-satisfied">
<!-- conditional tasks here -->
:
:
</target>
<target name="main" depends="conditional-step">
:
<condition property="condition-satisfied">
<available .../>
:
</condition>
<antcall target="condition-satisfied"/>
:
</target>
The advantage of this approach is to quickly have some tasks execute
conditionally by putting them in a target and calling that target using
antcall after setting some property.
And it seemed to work. My question is - is there a problem using this
approach? Why or why isn't this a preferred approach?
Thanks in advance,
Sandip