Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to handle old snapshots in local repository?

We have a Nexus local repository manager which handles all our internal projects (as well as mirroring outside repositories). For our internal projects, we only keep the most recent version's snapshot builds. For example if we had ProjectX 1.0, 1.1 and 1.2-SNAPSHOT, as soon as 1.2 was released we would delete 1.2-SNAPSHOT and then have 1.0, 1.1, 1.2 and 1.3-SNAPSHOT in our Nexus repository.

The problem is that our Jenkins server has all the OLD snapshots in its local .m2/repository folder and continues to build projects successfully against these old snapshots, when in reality they should be failing (and our developers should be fixing their POM files.)

Can Maven be configured (in settings.xml or pom.xml) to delete these unwanted snapshots if they are not present in the Nexus repository?

If not, what's the best way to get rid of them? Jenkins configuration, cron job, other option?

Thanks...

like image 798
user1071914 Avatar asked Mar 15 '12 22:03

user1071914


1 Answers

On Linux, you can use this command:

find $HOME/.m2/repository/ \
   -name "*-SNAPSHOT" \
   -type d \
   -mtime +60 \
   -print \
   -prune \
   -exec rm -r "{}" \;

Explanation:

  • Find anything named *-SNAPSHOT in the folder $HOME/.m2/repository/
  • AND it must be a directory
  • AND it must not have been modified in the last 60 days
  • Print what you found. If you want to test the command, stop here
  • The -exec will delete the folder, -prune tells find not to try to enter the folder afterwards.
  • The -exec will delete the folder and files inside.
like image 95
Aaron Digulla Avatar answered Oct 25 '22 14:10

Aaron Digulla