【问题标题】:Ant input called multiple times if used with ant-contrib foreach task如果与 ant-contrib foreach 任务一起使用,则多次调用 Ant 输入
【发布时间】:2015-11-03 01:44:25
【问题描述】:

我在 build.xml 文件中有这段代码 sn-p。

<input message="Please enter environment:" addproperty="environment" defaultvalue="dev"/>

<target name="DeployComposites">
  <echo>Deploying projects ${composite.list}</echo>
  <foreach list="${composite.list}" param="compositeName" target="compile-and-deploy" inheritall="false"/>
</target>

输入多次提示属性值。有没有办法让它只询问一次

【问题讨论】:

    标签: ant ant-contrib


    【解决方案1】:

    foreach 的工作方式为每次调用所需目标创建一个新的 Ant Project。由于您在顶层有 input,因此每次创建新的 Project 时都会调用它。

    相反,将其放在另一个目标中,例如

    <target name="get-env">
      <input message="Please enter environment:" addproperty="environment" defaultvalue="dev"/>
    </target>
    
    <target name="DeployComposites" depends="get-env">
      <echo>Deploying projects ${composite.list}</echo>
      <foreach list="${composite.list}" param="compositeName" target="compile-and-deploy" inheritall="false"/>
    </target>
    

    【讨论】:

    • 这里的问题是我需要在 ant 目标之前加载属性。该属性又加载一个属性文件。
    • @Raj 因此您还需要将该属性文件的加载移动到目标内。
    • 移动会使属性对其他目标不可用。有没有办法解决它
    • @Raj 使“其他目标”依赖于这个。
    • @Raj 你可以尝试在foreach 上设置inheritall="true" 而不是false - 如果已经设置了input 任务,则应该静默跳过它配置为填充的属性。
    猜你喜欢
    • 1970-01-01
    • 2011-07-04
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    相关资源
    最近更新 更多