tags:

views:

39

answers:

2

When running ant, how do I make an <available /> block throw an adequate error message?

This is what I have so far:

<target name="requirements">
  <available classname="foo.bar.baz" property="baz.present" />
</target>

<target name="directories" depends="requirements" if="baz.present">
  <mkdir dir="build" />
</target>

<target name="compile" depends="directories">
  <!-- build some stuff -->
</target>

What I'm currently seeing when requirements fails is a message complaining about the ./build dir not being available. How can I change this so that a message is displayed about the missing class, such as "foo.bar.baz is not available"?

+2  A: 

How about adding a fail to the compile target?

<fail message="foo.bar.baz is not available, stopping build!" 
      unless="baz.present"/>

This stops the current build with a meaningful error message. See the ant documentation of the Fail Task: http://ant.apache.org/manual/CoreTasks/fail.html

pitpod
A: 

The task <available> itself does not block, however you can use it in combination with <fail>: http://ant.apache.org/manual/CoreTasks/fail.html

fikovnik