问题
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:
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.
回答1:
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.
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"/>
来源:https://stackoverflow.com/questions/6979583/target-overriding-in-ant