ivan_ivanovich_ivanoff
ivan_ivanovich_ivanoff

Reputation: 19453

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:

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>

Upvotes: 7

Views: 10941

Answers (3)

Aaron Digulla
Aaron Digulla

Reputation: 328614

There are two ways to achieve this:

  1. You can do this with antcall.

  2. Since ant 1.6, you can use macros.

Upvotes: 14

Jeffrey Fredrick
Jeffrey Fredrick

Reputation: 4503

What you want is macro-def.

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

Upvotes: 2

John McG
John McG

Reputation: 698

<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

Upvotes: 0

Related Questions