Ant and the available task - what if something is not available?

ant, build, java

Solution

You can use a condition in combination with not:

http://ant.apache.org/manual/Tasks/condition.html

  <condition property="fooDoesNotExist">
    <not>
      <available filepath="path/to/foo"/>
    </not>
  </condition>

Problem

When I use the task, the property is only set to TRUE if the resource (say file) is available. If not, the property is undefined. When I print the value of the property, it gives true if the resource was available, but otherwise just prints the property name. Is there a way to set the property to some value if the resource is not available? I have tried setting the property explicitly before the available check, but then ant complains: ``` [available] DEPRECATED - used to override an existing property. [available] Build file should not reuse the same property name for different values. ```

Original source