自 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>