How to clean old dependencies from maven repositories?

前端 未结 9 1757
小鲜肉
小鲜肉 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: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.

提交回复
热议问题