【发布时间】:2012-06-29 05:13:02
【问题描述】:
这就是我想要达到的目标:
如果设置了属性,则调用 antcall 目标。这是可行的吗?谁能告诉我怎么做?
<condition>
<isset property="some.property">
<antcall target="do.something">
</isset>
</condition>
【问题讨论】:
标签: ant build build-automation
这就是我想要达到的目标:
如果设置了属性,则调用 antcall 目标。这是可行的吗?谁能告诉我怎么做?
<condition>
<isset property="some.property">
<antcall target="do.something">
</isset>
</condition>
【问题讨论】:
标签: ant build build-automation
这样的事情应该可以工作:
<if>
<isset property="some.property"/>
<then>
<antcall target="do.something"/>
</then>
</if>
如果 then 条件需要 ant-contrib,但在 ant 中任何有用的东西也是如此。
【讨论】:
我知道我真的迟到了,但是如果您使用的是不支持嵌套 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了解更多关于条件的信息。
【讨论】:
<target name="TaskUnderRightCondition" if="${someval eq someOtherVal}" />的事情吗?
考虑一下,您也可以为这些目的调用 groovy:
<use-groovy/>
<groovy>
if (Boolean.valueOf(properties["some.property"])) {
ant.project.executeTarget("do.something")
}
</groovy>
【讨论】: