John M
John M

Reputation: 41

Ivy deletion of unwanted (older) artifacts from Ivy cache

I have a local Artifactory repository in which I have two jars for commons-logging: one for version 1.0.4 and one for version 1.1.1. I'm experimenting with using Ivy to download the older one with an ant task (with the proper dependency tag in ivy.xml), and then I change the "rev" attribute of this dependency tag to 1.1.1.

When using ivy:resolve in ant, this newer jar gets successfully downloaded to my cache, but the older one is not deleted automatically, and I'd like to make this happen.

I can't figure out how to do so after looking at the Ivy documentation; does anyone know how to get Ivy to delete old versions of artifacts when newer ones are downloaded, either with the resolve task or something else?

Upvotes: 4

Views: 8205

Answers (2)

David W.
David W.

Reputation: 107070

There's really no issue with having the "older" jar in your cache. If your project doesn't need the older jar, Ivy will simply ignore it. The old jar takes up about 50 kilobytes in your system. In the age of Terabyte drives, it's not worth the time and effort to free the space.

The Ivy cache is just that: A cache. It is for ALL of your projects that use Ivy. If an older project requires that 1.0.4 version of the commons-logging jar, it will already be in the Ivy cache and doesn't have to be downloaded, thus, like a good caches, it saves you time and effort.

You can do an <ivy:cleancache> but that really scrubs your entire cache: Everything will be deleted. It will get rid of the older 1.0.4 version of the jar, but it also will get rid of the 1.1.1 version of the jar too. Of course, Ivy will just download it the next time its requested, but that means waiting for Ivy to download all of your jars.

By the way, that's one big problem with <ivy:cleancache>: If you're doing multiple builds with Ivy and one cleans the cache on you, you'll end up breaking the other builds. Normally, this isn't an issue with individual users, but it can be for a Continuous Integration system.

If you look at the Ivy documentation, it does say that an <ivy:cleancache> is the same as:

<delete dir="${ivy.cache.dir}" />

You could use that as a basis for removing older jars by using a date selector:

<delete dir="${ivy.cache.dir}">
    <date datetime="01/01/2010 12:00 AM" when="before"/>
    <include name="*.jar"/>
</delete>

However, that uses the modified date of the jar and not the date the jar was created.

Ignore your Ivy cache directory and don't worry about it. If the Ivy cached does get too big, you can delete it and Ivy will simply redownload new jars as required.

Upvotes: 4

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77991

I always include an ANT "realclean" target that additionally purges my ivy cache.

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

<target name="realclean" depends="clean">
    <ivy:cleancache/>
</target>

Doco

Upvotes: 2

Related Questions