如何强制执行最终的ant目标而不考虑依赖关系 [英] How to force a final ant target to execute regardless of dependencies

查看:96
本文介绍了如何强制执行最终的ant目标而不考虑依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的ant脚本,可以在其中将一组文件复制到任何目标外部的目录中.然后,我想在运行任何/所有目标之后,不管依赖项如何,都清理那些文件.我遇到的主要问题是目标可以是编译"或"deploywar",所以我不能只是从编译"中盲目地调用"cleanUp"目标,因为下一步可能会调用"deploywar".而且我不能仅仅从"deploywar"中盲目打电话,因为它可能不会被调用.我如何定义一个在所有其他必要目标都完成之后(失败或成功)将被调用的目标?下面的"cleanUpLib"目标是我想在所有/任何任务执行后调用的目标:

I have a basic ant script in which I copy a set of files into a directory outside of any target. I would then like to clean those files up after any/all targets have run regardless of dependencies. The main problem I'm having is that the target can be 'compile' or 'deploywar' so I can't just blindly call the 'cleanUp' target from 'compile' because 'deploywar' might get called next. And I can't blindly call from just 'deploywar' because it might not get called. How can I define a target that will get called after all other necessary targets have been completed (either failed or successful)? The 'cleanUpLib' target below is the target I would like to have called after all/any tasks have executed:

<project name="proto" basedir=".." default="deploywar">
...
<copy todir="${web.dir}/WEB-INF/lib">
    <fileset dir="${web.dir}/WEB-INF/lib/common"/>
</copy>
<target name="compile">
    <!-- Uses ${web.dir}/WEB-INF/lib -->
    ....
</target>

<target name="clean" description="Clean output directories">
    <!-- Does not use ${web.dir}/WEB-INF/lib -->
    ....
</target>

<target name="deploywar" depends="compile">
    <!-- Uses ${web.dir}/WEB-INF/lib -->
    ....
</target>

<target name="cleanUpLib">
    <!-- Clean up temporary lib files. -->
    <delete>
        <fileset dir="${web.dir}/WEB-INF/lib">
            <include name="*.jar"/>
        </fileset>
    </delete>
</target>

推荐答案

Rebse指向的构建侦听器解决方案看起来很有用(+1).

The build listener solution pointed to by Rebse looks useful (+1).

您可以考虑的另一种方法是超载"您的目标,如下所示:

An alternative you could consider would be to "overload" your targets, something like this:

<project default="compile">

    <target name="compile" depends="-compile, cleanUpLib" 
        description="compile and cleanup"/>

    <target name="-compile">
        <!-- 
            your original compile target 
        -->
    </target>

    <target name="deploywar" depends="-deploywar, cleanUpLib" 
        description="deploywar and cleanup"/>

    <target name="-deploywar">
        <!-- 
            your original deploywar target
        -->
    </target>

    <target name="cleanUpLib">
    </target>

</project>

您当然不能在单个Ant构建文件中真正过载,因此目标名称必须不同.

You can't really overload in a single Ant build file of course, so the target names must be different.

(我使用了-"前缀,这是使目标私有"的一种技巧-即由于shell脚本arg的处理,您不能从命令行调用它们.但是当然,您仍然可以加倍-在Ant中成功单击它们.

(I've used the "-" prefix above which is a hack to make targets "private" - i.e. you can't invoke them from the command line due to shell script arg processing. But of course you could still double-click them successfully in Ant).

这篇关于如何强制执行最终的ant目标而不考虑依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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