Target overriding in Ant
Asked Answered
M

1

18

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.

Mansoor answered 8/8, 2011 at 8:44 Comment(0)
T
30

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"/>
Tetrapterous answered 8/8, 2011 at 14:58 Comment(1)
Cool, that's the thing I've wanted and no-one answered to me) Thank you!Mansoor

© 2022 - 2024 — McMap. All rights reserved.