How to clean old dependencies from maven repositories?

前端 未结 9 1759
小鲜肉
小鲜肉 2020-12-14 05:19

I have too many files in .m2 folder where maven stores downloaded dependencies. Is there a way to clean all old dependencies? For example, if there is a dependency with 3 di

相关标签:
9条回答
  • 2020-12-14 06:05

    Just clean every content under .m2-->repository folder.When you build project all dependencies load here.

    In your case may be your project earlier was using old version of any dependency and now version is upgraded.So better clean .m2 folder and build your project with mvn clean install.

    Now dependencies with latest version modules will be downloaded in this folder.

    0 讨论(0)
  • 2020-12-14 06:06

    I wanted to remove old dependencies from my Maven repository as well. I thought about just running Florian's answer, but I wanted something that I could run over and over without remembering a long linux snippet, and I wanted something with a little bit of configurability -- more of a program, less of a chain of unix commands, so I took the base idea and made it into a (relatively small) Ruby program, which removes old dependencies based on their last access time.

    It doesn't remove "old versions" but since you might actually have two different active projects with two different versions of a dependency, that wouldn't have done what I wanted anyway. Instead, like Florian's answer, it removes dependencies that haven't been accessed recently.

    If you want to try it out, you can:

    1. Visit the GitHub repository
    2. Clone the repository, or download the source
    3. Optionally inspect the code to make sure it's not malicious
    4. Run bin/mvnclean

    There are options to override the default Maven repository, ignore files, set the threshold date, but you can read those in the README on GitHub.

    I'll probably package it as a Ruby gem at some point after I've done a little more work on it, which will simplify matters (gem install mvnclean; mvnclean) if you already have Ruby installed and operational.

    0 讨论(0)
  • 2020-12-14 06:08

    I came up with a utility and hosted on GitHub to clean old versions of libraries in the local Maven repository. The utility, on its default execution removes all older versions of artifacts leaving only the latest ones. Optionally, it can remove all snapshots, sources, javadocs, and also groups or artifacts can be forced / excluded in this process. This cross platform also supports date based removal based on last access / download dates.

    https://github.com/techpavan/mvn-repo-cleaner

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