Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target overriding in Ant

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.

like image 935
shaman.sir Avatar asked Aug 08 '11 08:08

shaman.sir


People also ask

How do I override property value in ant?

Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.

What is target in Ant build?

A target is a container of tasks and datatypes that cooperate to reach a desired state during the build process. Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target.

What is the default target in ant?

the default target to use when no target is supplied. No; however, since Ant 1.6. 0, every project includes an implicit target that contains any and all top-level tasks and/or types. This target will always be executed as part of the project's initialization, even when Ant is run with the -projecthelp option.

How do I run a specific target in ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.


1 Answers

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"/>
like image 76
Brett Kail Avatar answered Oct 17 '22 01:10

Brett Kail