Can I write an ant task which takes parameters when being executed from another ant task?
What I try to achieve in general, is re-using existing tasks with different parameters.
What I don't know is:
Concept of what I need to achieve:
Sub Ant task, which takes parameters param1 and param2:
<someAntCommand att="$param1"/>
<someOtherAntCommand att="$param2"/>
Main Ant task, which executes the sub task:
<doSomethingToExecSubTask somePointerToTaskOrFile="...">
<param name="param1"> hello </param>
<param name="param2"> world </param>
</doSomethingToExecSubTask>
<doSomethingToExecSubTask somePointerToTaskOrFile="...">
<param name="param1"> hello </param>
<param name="param2"> universe </param>
</doSomethingToExecSubTask>
Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.
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.
When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.
There are two ways to achieve this:
You can do this with antcall
.
Since ant 1.6, you can use macros.
What you want is macro-def.
For a really good guide to writing Ant macros check out this presentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With