java Ant 中的目标覆盖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6979583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Target overriding in Ant
提问by shaman.sir
Is there a possibility to literally override a target or emulate this somehow?
是否有可能从字面上覆盖目标或以某种方式模拟它?
So, when I call
所以,当我打电话
<target perform-after="release">
<do-something />
</target>
It will act like this:
它会像这样:
<target name="release">
<antcall target="release" /> <!-- call previous version, not recursion -->
<do-something />
</target>
I think it has a meaning, I'll describe on Android example:
我认为它有一个含义,我将在Android示例中描述:
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.
我们.xml
为每个build.xml
SDK 文件夹 ( {$SDK}/tools/ant/*.xml
) 中的每个都有一个模板,这些文件包含在build.xml
为每个项目生成的每个文件中。只有-pre-compile
,-pre-build
和-post-compile
目标为空且易于覆盖。但是没有空的-post-release
目标,例如。Google 建议在生成的build.xml
评论中只是将目标复制粘贴到我自己的目标build.xml
,然后对其进行调整。但我认为这是不行的,因为如果 Google 会在模板中更改此目标中的某些内容,我将永远不会知道我使用的是过时的版本。
回答by Brett Kail
See the "Target overriding" section of the importtask or the "Target rewriting" section of the includetask. In short, give the common build.xml a project name like "common", and then use "common.release" in the antcall.
请参阅导入任务的“目标覆盖”部分或包含任务的“目标重写”部分。总之,给common build.xml一个像“common”这样的项目名,然后在antcall中使用“common.release”。
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:
我会注意到 antcall 并不完全相同,因为它在运行时启动一个新项目,这意味着目标设置的变量稍后将不可见。我在这台机器上没有可用的 Ant 来测试,但你可以尝试这样的事情来避免 antcall:
<target name="release" depends="common.release, -post-release"/>