antcall based on a condition

Something like this should work:

<if>
    <isset property="some.property"/>
    <then>
        <antcall target="do.something"/>
    </then>
</if>

If then conditions require ant-contrib, but so does just about anything useful in ant.


I know I'm really late to this but here is another way to do this if you are using an of ant-contrib where if doesn't support a nested antcall element (I am using antcontrib 1.02b which doesn't).

<target name="TaskUnderRightCondition" if="some.property">
  ...
</target>

You can further expand this to check to see if some.property should be set just before this target is called by using depends becuase depends is executed before the if attribute is evaluated. Thus you could have this:

<target name="TestSomeValue">
  <condition property="some.property">
    <equals arg1="${someval}" arg2="${someOtherVal}" />
  </condition>
</target>

<target name="TaskUnderRightCondition" if="some.property" depends="TestSomeValue">
  ...
</target>

In this case TestSomeValue is called and, if someval == someOtherVal then some.property is set and finally, TaskUnderRightCondition will be executed. If someval != someOtherVal then TaskUnderRightCondition will be skipped over.

You can learn more about conditions via the documentation.