How to set an Ant property only if it is unset

ant

I can't figure out how to set an Ant property on the condition that it has not been set (i.e it is not defined in the properties file and should automatically default).

So far, I only have the following code:

<condition property="core.bin" value="../bin">
    <isset property="core.bin"/>
</condition>

But this only seems to work if the value is defined in a <property> tag.

Does anyone know how to conditionally set a property for the first time if it currently unset?

Best Answer

You simply can set the property with the property-task. If the property is already set, the value is unchanged, because properties are immutable.

But you can also include 'not' in your condition:

<condition property="core.bin" value="../bin">
   <not>  
      <isset property="core.bin"/>
   </not>
</condition>
Related Topic