How to over-write the property in Ant?

Priya picture Priya · Dec 8, 2009 · Viewed 63.2k times · Source

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

Answer

skaffman picture skaffman · Dec 8, 2009

ant-contrib's Variable task can do this:

<property name="x" value="6"/>
<echo>${x}</echo>   <!-- will print 6 -->
<var name="x" unset="true"/>
<property name="x" value="12"/>
<echo>${x}</echo>   <!-- will print 12 -->

Not recommended, though, it can lead to weird side-effects if parts of your Ant scripts assume immutable property values, and other parts break this assumption.