【问题标题】:ant conditional import蚂蚁条件导入
【发布时间】:2010-06-22 15:41:48
【问题描述】:

如果设置了属性,是否可以在 ant 的 build.xml 中导入文件,如果没有,则不要导入它。

除了使用 ant-contrib if 任务之外,还有其他方法吗?

谢谢

【问题讨论】:

    标签: ant


    【解决方案1】:

    是的,你可以。 例如:

    <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.7 开始,您不能在目标内使用 import。它必须是顶级任务
    • 哎呀,我的错。另外,导入任务的可选属性对你来说还不够吗?
    【解决方案2】:

    这是一个相当古老的问题,但从 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>
    

    【讨论】:

      猜你喜欢
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 2010-10-28
      • 1970-01-01
      • 2010-09-29
      • 1970-01-01
      相关资源
      最近更新 更多