For all those that where seeking for a method to roll out outdated artifacts from their Maven repository like me, but could not find a solution. Here is a simple shell script doing that work for you.

This script assumes that you have your maven repository in your home directory. It will delete all jar, swf and swc artifacts not used for AGE (31) days. Perhaps this script also works on Windows using Cygwin, but this is untested.

  #!/bin/sh

  M2_REPO=${HOME}/.m2
  OLDFILES=/tmp/oldfiles.txt
  AGE=31

  find "${M2_REPO}" -name '*jar' -atime +${AGE} -exec dirname {} \; \\
    >> ${OLDFILES}
  find "${M2_REPO}" -name '*swf' -atime +${AGE} -exec dirname {} \; \\
    >> ${OLDFILES}
  find "${M2_REPO}" -name '*swc' -atime +${AGE} -exec dirname {} \; \\
    >> ${OLDFILES}
  for x in `cat ${OLDFILES}`; do rm -rf "$x"; done

Just copy and paste the script into a file like cleanM2.sh and set the file permissions with

  chmod 755 cleanM2.sh

Finally execute it with

  ./cleanM2.sh

Warning: Make sure that you have backups of artifacts that cannot be downloaded from remote anymore. For example some special SNAPSHOT versions that have been updated in the meantime will be lost, if the file was not used for one month.



Twitter Bookmark Maven Housekeeping: Cleanup your local repository on Linux  at del.icio.us Facebook Google Bookmarks Digg Maven Housekeeping: Cleanup your local repository on Linux Bookmark Maven Housekeeping: Cleanup your local repository on Linux  at YahooMyWeb

Trackbacks


Trackback specific URI for this entry
    No Trackbacks

Comments


    #1 Simon on 08/04/10 at 02:26 PM [Reply]
    *Thanks for this - helpful starting point.

    Just wanted to point out that the find command you use actually finds anything that *has* been used in the last 31 days. Removing the ! mark fixes this. My revised script that looks for zip files and strips out duplicates:

    #!/bin/sh

    M2_REPO=${HOME}/.m2
    OLDFILES=/tmp/oldfiles.txt
    AGE=31

    find "${M2_REPO}" -name '*jar' -atime +${AGE} -exec dirname {} \; >> ${OLDFILES}
    find "${M2_REPO}" -name '*zip' -atime +${AGE} -exec dirname {} \; >> ${OLDFILES}
    find "${M2_REPO}" -name '*swf' -atime +${AGE} -exec dirname {} \; >> ${OLDFILES}
    find "${M2_REPO}" -name '*swc' -atime +${AGE} -exec dirname {} \; >> ${OLDFILES}

    #for x in `sort ${OLDFILES} | uniq`; do rm -rf "$x"; done
    for x in `sort ${OLDFILES} | uniq`; do echo "$x"; done

    rm $OLDFILES
    #2 Joern Schimmelpfeng on 08/04/10 at 09:20 PM [Reply]
    *Args, you are right and I fixed it. Thanks a lot for sharing your info!

Add Comment

HTML-Tags will be converted to Entities.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA