Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear .m2 Maven folder?

Tags:

eclipse

maven

My computer runs Windows 10 and I work with Java and Eclipse. Recently Windows warned me that I'm running into short disk space and after some study I noticed that I have a folder named .m2 under my user's folder (C:\Users\MySelf) that occupies 202Gb.

I know this folder belongs to Maven. Since this folder is bigger than all my projects and their dependencies together, it seems to me that Maven is keeping unnecessary files, so I want to get rid of them.

Is is safe simply delete the folder contents or should I run some particular process in order to save space and keep Maven working well?

like image 269
AlexSC Avatar asked Oct 07 '15 11:10

AlexSC


People also ask

Can I delete .m2 folder?

Cleanse your Maven repository by deleting the contents of the /. m2/repository directory. Ensure to delete the settings. xml file if so required.

What is Maven m2 folder?

m2 folder is the default folder used by maven to store its: settings. xml file which specifies properties, like the central repository to download your dependencies, the location of the so-called localRepository. by default, the localRepository in which maven stores all the dependencies your project might need to run.

How do I delete old dependencies in Maven?

In Maven, you can use Apache Maven Dependency Plugin, goal dependency:purge-local-repository to remove the project dependencies from the local repository, and re-download it again.


2 Answers

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.

like image 134
Adel Boutros Avatar answered Sep 29 '22 03:09

Adel Boutros


Solution 1:

You can even create new folder in D drive or any other drive. And use it.

Not necessary that you use .m2 folder created by default.

Also change this to new path:

<localRepository>D:\.m2\repository_Product</localRepository> 

Change setting as shown in image below:

Solution 2:

delete .m2 folder and then make sure that all the projects are having only new versions/required version of jar entry in pom.xml. Re-build the project. The .m2 folder will remain with only latest version

Tip: Keep your IDE and required projects open so that it will be prevented from deletion.

enter image description here

like image 36
VeKe Avatar answered Sep 29 '22 05:09

VeKe