Ant Best Practices: Provide a clean target

by Julian Simpson on April 6, 2008

(image taken from Bob Jagendorf’s photostream)


In the last post, we discussed the importance of good help. Today, the best practice we’re going to review (just joined us? have a look here) is provide a clean target. It’s pretty straightforward. As you change code (especially renaming source files), you’ll need to delete old files. You might as well automate the process.

I have seen builds that don’t use a clean target. But then generally these builds are relying on some other process, like nuking the entire checkout and starting again. It’s easier to have a clean target, honest.

You’d think that would be the end of it. Make a target called ‘clean’. Make it clobber some compiled code and generated artifacts. But while you go creating your new target, think about a couple of things:

- How many different files and directories do you need to delete? Ideally, it should be one directory. Life becomes very simple when you have a single tree to clean. Especially as you often end up making the opposite of a clean target to add directories back in.

- Did I say delete? If you have a single directory that the rest of the build depends on, check in into source control. You can often configure your VCS to ignore the contents (like cvsignore or svn:ignore) of the build directory. Then you can guarantee that it’s always there, but not have to worry about the built artifacts showing up when you go to commit.

Here’s one that I prepared earlier:

<project>
	<target name="clean">

	  <delete>
	    <fileset dir="${build.dir}">
	      <include name="**/*" />
	    </fileset>
	  </delete>
	 </target>
</project>

Eric. You’re on the money again.

Share with the group:
  • Digg
  • del.icio.us
  • Facebook
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon

Related posts:

  1. Story: Wolf++ fixes the Deployment Process The last of the top three stories for the...
  2. Ant will eat itself I was sorely tempted to save this for April...
  3. Versioning Derivative Artifacts Versioning the wrong things is an antipattern of software...
  4. The hidden cost of building Thanks to EJ Ciramella for this thought provoking post....
  5. SparkBuild – build optimisation This is a guest post from Scott Castle of...

Related posts brought to you by Yet Another Related Posts Plugin.

blog comments powered by Disqus

Previous post: CITCON Europe 2008, Amsterdam – registration is open

Next post: How to add Ant and NAnt support to TextMate