目标覆盖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.
推荐答案
请参阅导入的目标覆盖部分任务或包含任务的目标重写部分。简而言之,给公共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屋!