繁体   English   中英

如何将参数传递给ant任务的depends字段

[英]how to pass parameters to ant task's depends field

我有一个build.xml ,应该动态接收depends字段的参数。 我在其他一些app.xml定义此参数,例如:

ops=op1, op2, op3,op4,op5,.... opn

然后将这个app.xml导入build.xml并想在那里使用参数ops

<project name="Project" basedir="." default="help">
    <target name="test" depends="{$ops}" description="executea series of commands in ant">
      <echo message="batch operation job done.  tasks = {$ops}"/>
    </target>
</project>

如何将参数从一个ant文件传递到另一个?

depends参数不具有属性。

Ant使用依赖性矩阵来确定应该构建什么以及以什么顺序构建。 该矩阵是执行构建文件本身的任何部分之前计算的,因此完成此操作后甚至不会设置属性。

你想达到什么目的? 也许我们有一个更好的主意,您想要什么,我们可以为您提供帮助。 Ant不是像BASH或Python这样的脚本语言。

如前所述,您不能将属性放入Depends字段。 但是,如果要设置属性,则可以在If字段中使用它。

<project name="appProject">

  <target name="test" depends="target1,target2,target3" description="execute series of commands"/>

  <target name="target1" if="do.target1">
    <echo message="Target1 executed." />
  </target>

  <target name="target2" if="do.target2">
    <echo message="Target2 executed." />
  </target>

  <target name="target3" if="do.target3">
    <echo message="Target3 executed." />
  </target>

</project>

然后,在build.xml中设置给定的目标标志do.target1,do.target2或do.target3并执行它。 基本上就是您想要的。 在“如果”字段中,仅检查属性的值。 同样,您不必为属性使用$ {}结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM