If isset in apache ant is failing

Thanasis Pap picture Thanasis Pap · Jun 8, 2013 · Viewed 14.7k times · Source

I am trying to check if a property exists in ant with the following:

<target name="test">
    <property name="testproperty" value="1234567890"/>
    <if>
        <isset property="testproperty"/>
        <then>
            <echo message="testproperty exists"/>
        </then>
        <else>
            <echo message="testproperty does not exist"/>
        </else>
    </if>
</target>

The result is a failure with the message:

build.xml:536: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

I must be doing something wrong with isset as the following runs smoothly:

<target name="test">
    <property name="testproperty" value="1234567890"/>
    <echo message="'${testproperty}'"/>
</target>

Please advice :)

Answer

Mark O&#39;Connor picture Mark O'Connor · Jun 8, 2013

The if task is not a standard ANT task. This is how conditional execution of a target works

<project name="demo" default="test">

  <target name="property-exists" if="testproperty">
    <echo message="testproperty exists"/>
  </target>

  <target name="property-no-exists" unless="testproperty">
    <echo message="testproperty does not exist"/>
  </target>

  <target name="test" depends="property-exists,property-no-exists">
  </target>

</project>