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

10,932

Solution 1

There are two ways to achieve this:

  1. You can do this with antcall.

  2. Since ant 1.6, you can use macros.

Solution 2

What you want is macro-def.

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

Share:
10,932
ivan_ivanovich_ivanoff
Author by

ivan_ivanovich_ivanoff

!!! Netbeans 6.7 RELEASED !!! C is far better and easier than Java! Why? It is easier to use void pointers and to do pointer arithmetic, than explaining the basic concepts of OOP to a C programmer. Joke of the century: PHP is good, because it works... "PHP programming" is an oxymoron. There is no PHP programming. There is only PHP scriptkidding. There are two types of people who use PHP: - those who don't know other languages, - and those who HAVE TO use it Java is to JavaScript what Car is to Carpet. The LHC is the wrong answer to the technological singularity.

Updated on June 04, 2022

Comments

  • ivan_ivanovich_ivanoff
    ivan_ivanovich_ivanoff almost 2 years

    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>
    
  • botchniaque
    botchniaque over 10 years
    Very good presentation indeed. Thanks for sharing. That's what I needed.