Ant 中的目标覆盖 [英] Target overriding in Ant
问题描述
是否有可能从字面上覆盖目标或以某种方式模拟它?
Is there a possibility to literally override a target or emulate this somehow?
所以,当我打电话
<target perform-after="release">
<do-something />
</target>
它会像这样:
<target name="release">
<antcall target="release" /> <!-- call previous version, not recursion -->
<do-something />
</target>
我认为它是有含义的,我将在 Android 示例中描述:
I think it has a meaning, I'll describe on Android example:
我们为 SDK 文件夹中的每个 build.xml
都有一个 .xml
模板 ({$SDK}/tools/ant/*.xml
),这些文件包含在每个项目的每个生成的 build.xml
中.只有 -pre-compile
、-pre-build
和 -post-compile
目标为空且易于覆盖.但是没有空的 -post-release
目标,例如.Google 建议在生成的 build.xml
注释中只是将目标复制粘贴到我自己的 build.xml
中,然后对其进行调整.但我认为这是不行的,因为如果 Google 在模板中更改此目标中的某些内容,我将永远不会知道我使用的是过时的版本.
We have an .xml
templates for every build.xml
in SDK folder ({$SDK}/tools/ant/*.xml
), these files are included in every generated build.xml
for each project. There are only -pre-compile
, -pre-build
and -post-compile
targets that empty and easy to override. But there is no empty -post-release
target, for example. Google recommends in generated build.xml
comments just to copy-paste a target to my own build.xml
and then tune it. But I think it is not ok, because if Google will change something in this target inside a template, I will never know about I am using outdated version.
推荐答案
请参阅 import 任务或 include 的目标重写"部分 任务.简而言之,给common build.xml 取个common"之类的项目名,然后在antcall中使用common.release".
See the "Target overriding" section of the import task or the "Target rewriting" section of the include task. In short, give the common build.xml a project name like "common", and then use "common.release" in the antcall.
我会注意到 antcall 并不完全相同,因为它在运行时启动一个新项目,这意味着目标设置的变量稍后将不可见.我在这台机器上没有可用的 Ant 来测试,但你可以尝试这样的事情来避免 antcall:
I'll note that antcall isn't quite the same since it starts a new project at runtime, which means variables set by the target won't be visible later. I don't have Ant available on this machine to test, but you might try something like this to avoid the antcall:
<target name="release" depends="common.release, -post-release"/>
这篇关于Ant 中的目标覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!