自 Ant 1.9.1 起,可以使用特殊命名空間在所有任務和巢狀元素上新增 if 和 unless 屬性。
若要使用此功能,您需要新增下列命名空間宣告
xmlns:if="ant:if" xmlns:unless="ant:unless"
if
和 unless
命名空間支援下列 3 個條件
true
blank
set
<project name="tryit" xmlns:if="ant:if" xmlns:unless="ant:unless"> <exec executable="java"> <arg line="-X" if:true="${showextendedparams}"/> <arg line="-version" unless:true="${showextendedparams}"/> </exec> <condition property="onmac"> <os family="mac"/> </condition> <echo if:set="onmac">running on MacOS</echo> <echo unless:set="onmac">not running on MacOS</echo> </project>