Best way to handle old snapshots in local repository? Best way to handle old snapshots in local repository? jenkins jenkins

Best way to handle old snapshots in local repository?


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.


We use a similar setup here. We have nexus automatically delete snapshots once the artifact is released (for some repositories). Then on our continuous server, we just have a cron job that once a day deletes the local repository folder. This works well for us.