Cleaning your project between builds using Ant

Author: Jakob Jenkov, 10/4/07
Keywords: ANT, Build script
Abstract: This article explains how to use ANT to clean auto-generated files and compiled classes between builds.
subscribe to my RSS feed


Bookmark and Share


Cleaning your project between builds using Ant

The process of cleaning your project between builds is intended to make sure that the newly build code represents a build of the project as it looks at the build time. If you do not clean the project you can risk that some files are not rebuilt and thus represent an older version of some class or file.

Another good reason for cleaning up compiled classes and generated files is to make sure that deleted files and classes are not by accident left in the build dir, and included in future builds. By cleaning the project you make sure that no files are kept from the previous build.

Cleaning your project is easy. If all compiled classes and auto-generated files (JavaDoc etc.) are kept in the "build" directory, then simply delete this directory and create it again. That will clean up any files from earlier builds. It can be done using the following Ant target:

<?xml version="1.0"?>
<project name="techlopedia" default="clean" basedir=".">

    <property name="dir.build"    value="build"/>

    <target name="clean" >
        <delete dir="${dir.build}"/>
        <mkdir  dir="${dir.build}"/>
    </target>
</project>
 

You may want to have more than one clean target. For instance, if your project depends on 4 other projects, you may want to rebuild all 5 projects before a release. During development though, you may only want to build the one project you are working in, and not the 4 others. This is done to decrease build-time during development.

You may setup two different clean targets. A clean-all and a clean-project target. The clean-all target will delete all compiled classes and JAR-files from the build-directory, for all 5 projects. The clean-project will only delete what this project is generating of classes and JavaDoc. Not the compiled classes or JAR-files build from the 4 projects this project depends on.



Comments

If you have any comments to this article, please drop me a mail at firstclassthoughts at gmail dot com please indicate if I can't publish whole or parts of your comment on the site.


If you like this site consider subscribing to my RSS feed or how about subscribing by Email.


Help spread the word

Share this post on your favorite social bookmarking sites:
If you enjoyed this article, found it thought provoking, educative or otherwise good, please link to this page from your page or social bookmarking page. If you have any texts you think are worth publishing on First Class Thoughts, don't hesitate to send me a mail! Quality always welcome.


Bookmark and Share


The most recent contributions
28/07/09 Magic in mathematics II Fun with the number cyclic numbers, and specifically with 142857 as it is the smallest of such numbers.
13/07/09 My top 8 time-saving Firefox shortcuts This article presents my favorite top 8 time-saving shortcuts in Firefox 3.0 and Firefox 3.5. Get to know these and you'll be saving a lot of time. They have been ordered by "the element of most surprise"
20/05/09 Board Game Jungle speed / Arriba Review of the cool game "Jungle Speed" aka. "Arriba".
16/05/09 Danish Twin words "Twin words" are words that not only have multiple meanings, they must be composed next to each other in meaningful sentences. This article explores the concept of twin words.
Nothing of interest? Try browsing the entire article archive...