Best way to handle old snapshots in local repository?

落爺英雄遲暮 提交于 2019-12-06 18:46:54

问题


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...


回答1:


You may try the Maven Repo Cleaner Jenkins Plugin




回答2:


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.



回答3:


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.




回答4:


First if you are using jenkins to build the best practice to have clean builds which means to use a local repository per build and not the global of the server. Furthermore it sounds that you don't use the release plugin to release your artifacts which automatically checks if a pom contains SNAPSHOTs and would fail if there are some. Furthermore it's possible to clean up the local repository via the maven-dependency-plugin. Based on my experience i have simply configured a task which deletes SNAPSHOTs which are older than a month...




回答5:


It could be a configuration problem with maven on your jenkins server.

maven can and should be configured to periodically look for updated snapshots by configuring the value of <updatePolicy> in <repository> section for <snapshots>.

<updatePolicy>daily</updatePolicy>

The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never.

Also, if the version changes (from 1.1-SNAPSHOT to 1.2-SNAPSHOT), it is not clear how jenkins would successfully build with an older (1.1-SNAPSHOT) version.



来源:https://stackoverflow.com/questions/9729076/best-way-to-handle-old-snapshots-in-local-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!