Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an Ant property only if it is unset

Tags:

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?

like image 653
user64133 Avatar asked May 06 '09 09:05

user64133


People also ask

How do I override property value in Ant?

Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.

What is Basedir in Ant?

The 'basedir' is the base directory from which any relative directories used within the Ant build file are referenced from. If this is omitted the parent directory of the build file will be used.

Where are Ant properties set?

The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment.


1 Answers

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> 
like image 74
Mnementh Avatar answered Oct 03 '22 22:10

Mnementh