René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback

Ant, properties, precedence and a surprise

Here's something for developers using Ant. Consider the following build.xml file:
<project default="print_some_properties" name="Use Property Files">

  <property name="prop1" value="coke" />

  <property file="" />
  <property file="" />

  <property name="prop5" value="fanta" />

  <target name="print_some_properties" >
    <echo message="prop1: ${prop1}" />
    <echo message="prop2: ${prop2}" />
    <echo message="prop3: ${prop3}" />
    <echo message="prop4: ${prop4}" />
    <echo message="prop5: ${prop5}" />

As can be seen, if Ant is invoked with this build.xml file, it tries to build the default target print_some_properties. This target does nothing except printing the values of the five properties prop1 through prop5.
This build.xml alse references two property files that set some properties. Here's their content:
prop2=New York
prop3=San Francisco
Now, what do you think, will this print if Ant is invoked like so:
c:\> Ant
I didn't read the specification and I assumed that properties can and are overridden, that is, prop1 would be Chigaco (because it is overriden by, and that prop3 would be San Francisco. However, the output was:
Buildfile: build.xml

     [echo] prop1: coke
     [echo] prop2: New York
     [echo] prop3: apple
     [echo] prop4: pear
     [echo] prop5: banana

Total time: 0 seconds
I missed the following sentence in the Ant manual: Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definately not variable.