When is it safe to delete the local Maven repository?

前端 未结 4 1913
清歌不尽
清歌不尽 2020-12-10 01:27

In which circumstances is it safe respectively unsafe to rm -rf ~/.m2/repository provided that I\'m working online and I have access to all needed artifacts via

相关标签:
4条回答
  • 2020-12-10 01:49

    When you retrieve all dependencies from remote repositories, then the local repo becomes nothing more than a cache.

    Like all caches, the Maven local repo can occasionally become "dirty". In an acknowledged act of paranoia and overkill, I schedule a periodic cron job to purge the local repositories on my build machines. This forces a re-sync with my Nexus Maven repository.

    0 讨论(0)
  • 2020-12-10 02:01

    What you could do is add a cron entry to regularly delete files in the local repository for a given period, say 90 days.

    find ~/.m2/ -type f -atime +90 -delete && \
        find ~/.m2/ -type d -empty -delete
    

    This keeps your cache size down to only artifacts you've been using recently.

    0 讨论(0)
  • 2020-12-10 02:09

    If you have access to all needed artifacts via remote repos, it is always safe to remove local Maven repository. All artifacts needed to the next build, including even basic Maven plugins (like compiler) will be basically fetched from remote repos. That's it.

    0 讨论(0)
  • So instead of doing the "brute force" way, there is a different option:

    brute force:

    rm -rf ~/.m2/repository

    Here is the "mvn" way to do this.

    "everything:

    mvn dependency:purge-local-repository
    

    some arguments that I find helpful

    mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false
    

    Here is what I typically do for my local machine:

    mvn dependency:purge-local-repository -DmanualInclude="my.group.id" -DsnapshotsOnly=true  -DactTransitively=false -DreResolve=false
    

    you can investigate the command line options here:

    https://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html

    0 讨论(0)
提交回复
热议问题