Thursday, April 26, 2012

Dealing With Corrupt Maven Artifacts

Yesterday I was happily coding away, when Eclipse gave me a disturbing error:
Archive for required library: '/foo/bar.jar' in project 'Baz' cannot be read or is not a valid ZIP file
Now, since I use Maven3 for all my dependency handling, this seemed a rather strange error.  I went to the location of the artifact JAR in my Maven repository and sure enough the JAR file was corrupt!  'Odd', I thought, and deleted the version folder and tried to build again, thinking it would fetch the proper version this time.  Same error!  And the corrupt JAR file had returned!

I checked out the canonical copy on the actual Maven repository site and it was fine.  I trawled Google looking for similar situations and found Eclipse Bug 375249 which shows it to be a known bug in 3.6-Indigo but fixed in 3.7-Juno, with a suggested workaround.  The workaround didn't work, however.

I finally realised that the rebuild step above wasn't fetching the artifact JAR from the canonical Maven repository, but from our local Maven repository, which acts as a local cache for artifacts.  On a hunch, I deleted my local copy of the JAR, then the cached copy on our Archiva repository and rebuilt.  Success!

I have no idea why this one set of archives got corrupted when being pulled down by Archiva, but at least I can now fix the issue and carry on my development.

No comments:

Post a Comment