

Optionally inspect the code to make sure it's not malicious.Clone the repository, or download the source.Instead, like Florian's answer, it removes dependencies that haven't been accessed recently. 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. 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. I wanted to remove old dependencies from my Maven repository as well. The latest version of the above files can be found on my github. This means that versions 1.16.20 and 1.18.2 of lombok will be removed and 1.18.6 will be left untouched. The output will look like this: update /org/projectlombok/lombok You can get a log of what is going to be removed without actually removing it by setting dry_run = True. It can easily be restored with Maven (or other tools that manage dependencies).

Īny old versions, even ones that you actively use, will be removed. Then the script removes version 2.7.2 of antlr and what is left is. Say you have the following tree somewhere in your local Maven repo. It recursively searches within the local Maven repository you configured (normally ~/.m2/repository) and if it finds a catalog where different versions reside it removes all of them but the newest.

Run the script with python repo-cleaner.py. Make sure that you have Python 3.6+ installed and that the semver package has been installed into your global environment or venv (use pip install semver if missing). If current_pare(latest_version) > 0:Ĭonstants.py (edit to point to your own local Maven repo): # Paths Shutil.rmtree('/'.join())Ĭurrent_version = (directory) Print(directory + ' (Has newer version: ' + latest_version + ')') Print('Update ' + path.split(Constants.m2_path)) Latest_version = check_if_versions(directories)Ĭheck_and_clean('/'.join()) # Change to True to get a log of what will be removedĭirectories = Repo-cleaner.py: from os.path import isdir Maybe it will be useful for someone else also: So I wrote one myself in Python to get rid of old local artefacts.

It's been more than 6 years since this question was asked, but I still didn't find any tool to satisfactorily clean up my repository. Remove local mirror from config file and from file system. Now you have local maven repository with minimal of necessary artifacts.
