是否有可能从字面上覆盖目标或以某种方式模拟它?
所以,当我打电话
<target perform-after="release">
<do-something />
</target>
它将像这样:
<target name="release">
<antcall target="release" /> <!-- call previous version, not recursion -->
<do-something />
</target>
我认为它有意义,我将在Android示例中描述:
我们为 SDK 文件夹中的每个 build.xml
都有一个 .xml
模板 ({$SDK}/tools/ant/*.xml
),这些文件包含在为每个项目生成的每个 build.xml
中。只有 -pre-compile
、-pre-build
和 -post-compile
目标是空的且易于覆盖。但是,例如,没有空的 -post-release
目标。 Google 建议在生成的 build.xml
注释中将目标复制粘贴到我自己的 build.xml
中,然后对其进行调整。但我认为这不行,因为如果 Google 在模板中更改此目标中的某些内容,我将永远不会知道我使用的是过时版本。
最佳答案
请参阅 import 的“目标覆盖”部分任务或 include 的“目标重写”部分任务。简而言之,给common build.xml起一个像“common”这样的项目名,然后在antcall中使用“common.release”。
我会注意到 antcall 并不完全相同,因为它在运行时启动一个新项目,这意味着目标设置的变量稍后将不可见。我在这台机器上没有可用的 Ant 来测试,但你可以尝试这样的事情来避免 antcall:
<target name="release" depends="common.release, -post-release"/>
关于java - Ant 中的目标覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979583/