Search code examples
antpropertiestask

How to over-write the property in Ant?


Is there a way to re-assign the value for the Ant property task? Or is there another task available for that purpose?


Solution

  • Depending on how you want to use the modified property, you can use macrodefs.

    For example, instead of writing the following:

    <target name="foo">
       <echo message="${my_property}"/>
    </target>
    

    and not being able to call ant foo with another message, you could write:

    <macrodef name="myecho">
        <attribute name="msg"/>
        <sequential>
            <echo message="@{msg}"/>
        </sequential>
    </macrodef>
    
    <target name="foo">
       <myecho msg="${my_property}"/>
       <property name="my_property2" value="..."/>
       <myecho msg="${my_property2}"/>
    </target>