If 和 Unless

自 Ant 1.9.1 起,可以使用特殊命名空間在所有任務和巢狀元素上新增 ifunless 屬性。

若要使用此功能,您需要新增下列命名空間宣告

xmlns:if="ant:if"
xmlns:unless="ant:unless"

ifunless 命名空間支援下列 3 個條件

true
如果屬性的值評估為 true,則為 true
blank
如果屬性的值為 null 或空,則為 true
set
如果設定指定的屬性,則為 true
<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>