Search code examples
antbuild-process

Ant warning/failure when file / build.properties is missing?


My teams ant task pulls in developer specific info from a build.properties file by using the property file tag:

<property file="${user.home}/build.properties.txt" />

However, when this file is missing ant continues regardless. Later on in the build process it then tries to access properties that have not been defined and tries to log into the svn server as ${user.name} and other similar errors. These errors were quite difficult to debug, as some of the ant tasks I used did not give useful error messages.

My primary question is: Is there a way to ask ant to fail-fast if it cannot find the properties file?


Solution

  • I think you can combine available and fail:

    Sets the property if File is present

    <available file="${user.home}/build.properties.txt" property="build.properties.present"/>
    

    Fails if property is not set

    <fail unless="build.properties.present"/>