Fail

Description

Exits the current build (just throwing a BuildException), optionally printing additional information.

The message of the Exception can be set via the message attribute or character data nested into the element.

Parameters

Attribute Description Required
message A message giving further information on why the build exited No
if Only fail if a property of the given name exists in the current project No
unless Only fail if a property of the given name doesn't exist in the current project No
status Exit using the specified status code; assuming the generated Exception is not caught, the JVM will exit with this status. Since Apache Ant 1.6.2 No

Parameters specified as nested elements

As an alternative to the if/unless attributes, conditional failure can be achieved using a single nested <condition> element, which should contain exactly one core or custom condition. For information about conditions, see here.
Since Ant 1.6.2

Examples

Exit the current build with no further information given.

<fail/>
BUILD FAILED

build.xml:4: No message

Exit the current build and print a message to wherever your output goes:

<fail message="Something wrong here."/>
BUILD FAILED

build.xml:4: Something wrong here.

A different way to achieve the same result as above.

<fail>Something wrong here.</fail>

Exit the current build and print an explanation to wherever your output goes:

<fail unless="thisdoesnotexist"/>
BUILD FAILED

build.xml:2: unless=thisdoesnotexist

Use a condition to achieve the same effect:

<fail>
    <condition>
        <not>
            <isset property="thisdoesnotexist"/>
        </not>
    </condition>
</fail>
BUILD FAILED

build.xml:2: condition satisfied

Check that both files one.txt and two.txt are present otherwise the build will fail.

<fail message="Files are missing.">
    <condition>
        <not>
            <resourcecount count="2">
                <fileset id="fs" dir="." includes="one.txt,two.txt"/>
            </resourcecount>
        </not>
    </condition>
</fail>