Apache Ant target execute based on condition

July 21, 2011

To execute an Ant target based on condition, use the “if” attribute of the target,


<target name="build-module-A" if="module-A-present"/>

if the module-A-present property is set (to any value, e.g. false), the target will be run.

http://ant.apache.org/manual/targets.html#targets


<target name="use-file" depends="-check-use-file" if="${file.exists}">
</target>

As of Ant 1.8.0, you may instead use property expansion; a value of true (or on or yes) will enable the item, while false (or off or no) will disable it. Other values are still assumed to be property names and so the item is enabled only if the named property is defined.


http://ant.apache.org/manual/properties.html#if+unless

Advertisements