Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write an ant task which takes parameters when being executed from another ant task?

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:

  • is there something such a sub-task in ant?
  • can it take parameters?
  • how and where such sub-task is specified?

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>
like image 757
ivan_ivanovich_ivanoff Avatar asked Aug 25 '09 15:08

ivan_ivanovich_ivanoff


People also ask

What is true about Ant tasks?

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.

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.

What is Antcall target?

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.


2 Answers

There are two ways to achieve this:

  1. You can do this with antcall.

  2. Since ant 1.6, you can use macros.

like image 173
Aaron Digulla Avatar answered Nov 12 '22 01:11

Aaron Digulla


What you want is macro-def.

For a really good guide to writing Ant macros check out this presentation.

like image 31
Jeffrey Fredrick Avatar answered Nov 11 '22 23:11

Jeffrey Fredrick