【发布时间】:2010-06-22 15:41:48
【问题描述】:
如果设置了属性,是否可以在 ant 的 build.xml 中导入文件,如果没有,则不要导入它。
除了使用 ant-contrib if 任务之外,还有其他方法吗?
谢谢
【问题讨论】:
标签: ant
如果设置了属性,是否可以在 ant 的 build.xml 中导入文件,如果没有,则不要导入它。
除了使用 ant-contrib if 任务之外,还有其他方法吗?
谢谢
【问题讨论】:
标签: ant
是的,你可以。 例如:
<target name="importFile" depends="myProperty.check" if="myPropertyIsSet">
<echo>Import my file here</echo>
</target>
<target name="myTarget.check">
<condition property="myPropertyIsSet">
<and>
<!-- Conditions to check if my property is set. -->
</and>
</condition>
</target>
Apache Ant Manual 中描述了可用条件。
【讨论】:
这是一个相当古老的问题,但从 Ant 1.9.1 开始,您可以使用“if”属性进行条件导入:
<project name="cond-import" basedir="." xmlns:if="ant:if">
<condition property="script-exists">
<available file="other-ant-script.xml"/>
</condition>
<include if:set="script-exists" file="other-ant-script.xml"/>
</project>
【讨论】: