有没有一种方法可以在执行目标依赖项之前检查Ant目标条件 [英] Is there is a way to check Ant Target condition before target dependencies get executed
问题描述
我正在尝试避免在程序中使用antcall,因此尝试将antcall目标移至目标依赖项。现在我有一个情况:
I am trying to avoid antcall in my program, so trying to move antcall targets to target dependencies. Now I have a situation:
<target name="test" depends="a,b,c" />
<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="c1,c2,c3" />
现在一切正常。但是如果我只是想跳过目标'c'及其执行的依赖项,
Till now every thing work fine. But if i just want to skip target 'c' and its dependencies from execution,
<target name="c" depends="c1,c2,c3" if="skip.c" /> (considering the property "skip.c" is already set)
现在,目标 c的依赖项将执行然后检查条件 skip.c。
是否有更好的解决方案,其中目标及其依赖项都不会根据条件执行。
Now the dependencies of target 'c' will be executed and then it checks for condition "skip.c".
Is there a better solution, where both target and its dependencies wont execute based on condition.
如果条件允许,我总是可以去做antcall。但是正在寻找其他替代方法。
我无法检查c1,c2,c3目标中的 skip.c条件,因为我还有更多条件可以检查这些目标。
I can always go for antcall with if conditions. But looking for any another alternative.
I cant check for "skip.c" conditions in c1,c2,c3 targets as i have more conditions to check in those targets.
推荐答案
在查看如果/除非测试之前,将处理目标的所有依赖项。 Ant中没有内置方法可以避免这种情况。
All dependencies of a target are processed before the "if/unless" test is looked at. There is no built-in method in Ant to avoid this.
相反,好的方法是将依赖项与操作分开。请尝试以下操作:
Instead, a good approach is to separate the dependencies from the actions. Try the following:
<target name="test" depends="a,b,c" />
<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c">
<condition property="skip.c.and.dependents">
<or>
<isset property="prop1"/>
<isset property="prop2"/>
</or>
</condition>
<antcall target="do-c-conditionally"/>
</target>
<target name="do-c-conditionally" unless="skip.c.and.dependents">
<antcall target="do-c"/>
</target>
<target name="do-c" depends="c1,c2,c3">
<!-- former contents of target c -->
</target>
这篇关于有没有一种方法可以在执行目标依赖项之前检查Ant目标条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!