【问题标题】:Ant target with unless attribute not considering property value具有除非属性不考虑属性值的 Ant 目标
【发布时间】:2017-03-26 13:26:09
【问题描述】:

我使用QAF 与ant 作为构建脚本和IVY 作为依赖管理工具。为了自动 ivy 安装构建脚本有以下 ant 目标:

<target name="download-ivy" unless="skip.download">
    <mkdir dir="${ivy.jar.dir}" />
    <!-- download Ivy from web site so that it can be used even without any 
        special installation -->
    <echo message="installing ivy..." />
    <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true" />
</target>

有 build.properties,其中属性 skip.download 通过提供相应的值 truefalse 提供给下载常春藤 ON 或 OFF。

现在问题是我在 build.properties 中为 skip.download 提供的任何值,它认为它是 true,并且始终执行目标(下载 ivy)。

#not working
skip.download=false

我提到了IVY + Ant documentation,它具有类似的以下目标,但属性名称不同。

<target name="download-ivy" unless="offline">

    <mkdir dir="${ivy.jar.dir}"/>
    <!-- download Ivy from web site so that it can be used even without any special installation -->
    <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" 
         dest="${ivy.jar.file}" usetimestamp="true"/>
</target>

我找到了解决方法,因为解决方法需要删除或评论该属性才能跳过下载。

有什么方法可以使属性值正常工作,除非 目标中的属性?

【问题讨论】:

    标签: ant ivy qaf


    【解决方案1】:

    我使用以下目标来安装 ivy。请注意它如何使用可用任务来确定 ivy 是否已安装:

    <available classname="org.apache.ivy.Main" property="ivy.installed"/>
    
    <target name="install-ivy" description="Install ivy" unless="ivy.installed">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
        <fail message="Ivy has been installed. Run the build again"/>
    </target>
    

    注意:

    • 目录“$HOME/.ant/lib”是 ivy 用于加载第 3 方扩展的标准位置之一。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      相关资源
      最近更新 更多