Custom Search

Wednesday, June 26, 2013

Purging / Delete local maven (mvn) repository

Local mvn repository is nothing but a cache of part of the contents of online repository.
Sometimes it becomes messy with duplicate jars.
So, time to time we should clean the local maven repository (only when you should have internet access and can download again from online repositories):

maven repository is located in your systems, current users home / root path inside a directory named ".m2".

In windows it should be at : C:\Documents and Settings\<username>\

In Linux, it should be at :  ~  (root location)

in Unix, navigate to that directory and then delete the "repository" directory. and rebuild the pom.xml

Go to the root:
[root@www ~]# cd

List out the contents in root, with -a  attrribute, to show system, hidden files/directories too (basically files with all attributes will be listed):
[root@www ~]# ls -la
Result should show something like this below:

Delete the repository dir:
[root@www ~]# rm -rf ~/.m2/repository

[root@www ~]# cd .m2

[root@www .m2]# ls -l

total 0

Now again do a build of your project's pom file:
Navigate to your projects pom file directory:
# cd <projects workspace location containing pom.xml>
# mvn clean package

It should then download all required jars to the same repository again.

Otherwise you can use the command : mvn dependency:purge-local-repository
The default behaviour of the plugin is to first resolve the entire dependency tree, then delete the contents from the local repository, and then re-resolve the dependencies from the remote repository.