Make Ant's delete task fail when a directory exists and is not deleted but not when it doesn't exist

Posted by Tim Visher on Stack Overflow See other posts from Stack Overflow or by Tim Visher
Published on 2010-04-15T14:42:30Z Indexed on 2010/04/15 14:53 UTC
Read the original article Hit count: 301

Filed under:
|
|

I have tho following clean function in my build script and I'd like to know how I can improve it.

<target name="clean" description="Clean output directories.">
    <!-- Must not fail on error because it fails if directories don't exist.
         Is there really no better way to do this? -->
    <delete includeEmptyDirs="true" failonerror="false">
        <fileset dir="${main.build.directory}" />
        <fileset dir="dist" />
        <fileset dir="${documentation.build.directory}" />
        <fileset dir="/build-testing" />
    </delete>
</target>

Specifically regarding my comment, I'm unhappy with the fact that I can't run this on a fresh box because the directory structure hasn't been set up yet by the other targets. We run the build in such a way that it entirely recreates the structures necessary for testing and deployment every time to avoid stale class files and such. With the way that delete currently is set up, a failure to delete a file does not fail the build and I'd like it to. I don't want it to fail the build if the file doesn't exist though. If it doesn't exist then what I'm asking it to do has already happened.

Thoughts?

© Stack Overflow or respective owner

Related posts about ant

Related posts about delete