How to over-write the property in Ant?

Viewed 66102

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

8 Answers

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>
Related