views:

162

answers:

3

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>
+2  A: 
<property name="param1"/>
<property name="param2"/>
<target name="task1">        
    <property name="param1" value="hello"/>
    <property name="param2" value="world"/>        
</target>
<target name="task2">
</target>

Just call task2, task run will run before it

John McG
Apologies, copy and paste error! I have edited and this should solve it
John McG
+4  A: 

There are two ways to achieve this:

  1. You can do this with antcall.

  2. Since ant 1.6, you can use macros.

Aaron Digulla
Macros seem to be the right solution. Thanks!
ivan_ivanovich_ivanoff
A: 

What you want is macro-def.

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

Jeffrey Fredrick