How to Clean Old Dependencies from Maven Repositories

maven: how to clean the old snapshot in local repo?

mvn dependency:purge-local-repository might help. Take a look at the section about including specific groupId's or artifactId's.

clean up and maintain local maven cached artifact in .m2

If you don't care that external dependencies are pulled in every build, you could use a private Maven repository per job (Maven -> Advanced -> Check 'use private Maven repository') and clean the workspace at the start of your build. The private repository creates a .repository in your workspace, so cleaning your workspace will ensure you start with an empty repository.

Should you have many shared external dependencies, then you may be using even more diskspace, since they are present multiple times in the different repositories. In that case you could write a script that periodically (using a task scheduler like cron) removes unused files from the shared repository, see for example this Stack Overflow answer.

However be cautious with a shared Maven repository! Maven by default is not threadsafe, so concurrent jobs downloading the same artifact might use the incomplete downloads. Consider using the Takari extensions to make your Maven repository thread-safe.

How to remove jar file from local maven repository which was added with install:install-file?

While there is a maven command you can execute to do this, it's easier to just delete the files manually from the repository.

Like this on windows Documents and Settings\your username\.m2 or $HOME/.m2 on Linux

How to clear .m2 Maven folder?

It's perfectly safe to delete the folder .m2/repository as maven will re-download all the needed dependencies when needed except for your local projects. It there any other folder under .m2 taking space?

For your local projects, maven will complain about not finding them. In that case, you simply need to re-compile them and install them by running mvn clean install in each project folder. They will get uploaded to the repository.

Related Topics

Leave a reply