Sunday, July 03, 2011

Conditionally Call and Ant Target

If you want to set a target to only run if you set a particular value, easy. Just use the if attribute as follows:


<target name="whatever" if="my.value">
<echo message="target executed"/>
</target>


If you want the above target to run - set my.value to something in your property file before that target and it will run.


<property name="my.value" value="yada"/>

If you leave the property out of your file altogether the target won't run.

You can also have other tasks set values and use those values to determine if targets should run or not based on whether a file was available, etc. Details about conditional values can be found in the Ant FAQ:

Conditionally Execute Ant Target