有没有办法在执行目标依赖项之前检查 Ant 目标条件 [英] Is there is a way to check Ant Target condition before target dependencies get executed

查看:32
本文介绍了有没有办法在执行目标依赖项之前检查 Ant 目标条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的程序中避免 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.

我总是可以在 if 条件下使用 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.

推荐答案

在查看if/unless"测试之前处理目标的所有依赖项.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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆