Ant Tasks and the “update”-Property

harvester-ant-illustration_1500x1200

Ant’s default tasks include archiving tasks with which we can create zip, jar and war files in the course of our project’s build process. All these tasks offer the “update”-attribute for time-saving incremental builds. If this attribute is set to true, the target archive file will not be created from scratch if it already exists.

Rather, ant checks the contents of the existing archive file and compares them to the files which are supposed to be archived. Any files that are not already in the archive (or which have changed since the last build) are then put in the already existing archive, overwriting existing files:

<target name="jar-update">
<jar basedir="DirToJar" update="true" destfile="test.jar"/>
</target>

But what happens if you delete a file in the directory you want to archive? Does ant realize that you deleted the file and will also delete this file in the target archive file?

The answer to that question is: no, ant does not delete files from an archive file if the “update” atribute is set to “true”. This can lead to nasty surprises in some rare cases. However, deleting the target archive file (for example during a “clean”) solves this problem.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s