【问题标题】:antcall based on a condition基于条件的antcall
【发布时间】:2012-06-29 05:13:02
【问题描述】:

这就是我想要达到的目标:

如果设置了属性,则调用 antcall 目标。这是可行的吗?谁能告诉我怎么做?

<condition>
    <isset property="some.property">
        <antcall target="do.something">
    </isset>
</condition>

【问题讨论】:

标签: ant build build-automation


【解决方案1】:

这样的事情应该可以工作:

<if>
    <isset property="some.property"/>
    <then>
        <antcall target="do.something"/>
    </then>
</if>

如果 then 条件需要 ant-contrib,但在 ant 中任何有用的东西也是如此。

【讨论】:

  • 太棒了。为我工作。我对 Ant Contrib 没意见。
  • 应该是
【解决方案2】:

我知道我真的迟到了,但是如果您使用的是不支持嵌套 antcall 元素的 ant-contrib,这里有另一种方法(我使用的是 antcontrib 1.02b,它不支持)。

<target name="TaskUnderRightCondition" if="some.property">
  ...
</target>

您可以进一步扩展它以检查是否应该在调用此目标之前设置 some.property,方法是使用依赖,因为依赖是在评估 if 属性之前执行的。因此你可以有这个:

<target name="TestSomeValue">
  <condition property="some.property">
    <equals arg1="${someval}" arg2="${someOtherVal}" />
  </condition>
</target>

<target name="TaskUnderRightCondition" if="some.property" depends="TestSomeValue">
  ...
</target>

在这种情况下 TestSomeValue 被调用,如果 someval == someOtherVal 然后 some.property 被设置,最后,TaskUnderRightCondition 将被执行。如果 someval != someOtherVal 则 TaskUnderRightCondition 将被跳过。

您可以通过the documentation了解更多关于条件的信息。

【讨论】:

  • 你能做类似&lt;target name="TaskUnderRightCondition" if="${someval eq someOtherVal}" /&gt;的事情吗?
  • @siledh 我不知道。我不这么认为。
【解决方案3】:

考虑一下,您也可以为这些目的调用 groovy:

<use-groovy/>
<groovy>
   if (Boolean.valueOf(properties["some.property"])) {
     ant.project.executeTarget("do.something")
   }
</groovy>

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2022-10-15
    • 2014-09-20
    • 1970-01-01
    • 2018-10-27
    • 2013-11-12
    • 2016-01-15
    • 2012-09-11
    相关资源
    最近更新 更多