Phillip B Oldham
Phillip B Oldham

Reputation: 19385

Ant: make "available" throw an understandable error?

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"?

Upvotes: 2

Views: 194

Answers (2)

fikovnik
fikovnik

Reputation: 3603

The task <available> itself does not block, however you can use it in combination with <fail>.

Upvotes: 1

pitpod
pitpod

Reputation: 399

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.

Upvotes: 3

Related Questions