Locating bad maven artifacts in your maven proxy (or local repository)

By | July 10, 2012

Do you get a weird build failure caused by a dependency while it works for everyone else using the same (or similar) maven settings? I did and some research led me to believe that the local maven proxy contained one or more corrupted maven artifacts.

Here’s how to locate the bad artifacts:

  1. Empty your local maven repository at $HOME/.m2/repository by moving it to a different directory (to “repository.old”)
  2. Configure maven (in $HOME/.m2/settings.xml) to not use your local maven proxy (In my case Nexus)
  3. Execute the build that previously failed. Now it should work, because you’re getting the good version of the artifact.
  4. Restore the original settings.xml, move your local repository to repository.good. Now the build should fail again.
  5. Repeat step 3 (rename the repository directory to “repository.bad”)
  6. Find duplicates in repository.good and repository.bad, using fdupes or a similar tool, and delete them:
    fdupes -rdN repository.bad repository.good
  7. Compare the remaining, different artifacts in repository and repository.good
    These commands find the jar, ear and war-files which are present in both repositories, having different md5sums:

    cd repository.good
    for path in $(find . -type f|grep -vE '(sha|pom|md5)'); do if [ -e ../repository.bad/$path ]; then echo $path; fi; done
    

Once found, the bad artifacts must be deleted from your maven proxy.

Leave a Reply

Your email address will not be published. Required fields are marked *