eclipse 如何清除 .m2 Maven 文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32991258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:35:34  来源:igfitidea点击:

How to clear .m2 Maven folder?

eclipsemaven

提问by AlexSC

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 .m2under my user's folder (C:\Users\MySelf) that occupies 202Gb.

我的电脑运行 Windows 10,我使用 Java 和 Eclipse。最近,Windows 警告我磁盘空间不足,经过一些研究后,我注意到.m2我的用户文件夹 ( C:\Users\MySelf)下有一个文件夹,占用了 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.

我知道这个文件夹属于 Maven。由于这个文件夹比我所有的项目及其依赖项加起来都大,在我看来 Maven 保留了不必要的文件,所以我想摆脱它们。

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?

简单地删除文件夹内容是安全的,还是应该运行一些特定的过程以节省空间并保持 Maven 正常运行?

回答by Adel Boutros

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

删除文件夹.m2/repository是完全安全的,因为 maven 会在需要时重新下载所有需要的依赖项,除了您的本地项目.m2占用空间下还有其他文件夹吗?

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 installin each project folder. They will get uploaded to the repository.

对于您的本地项目,maven 会抱怨找不到它们。在这种情况下,您只需重新编译它们并通过mvn clean install在每个项目文件夹中运行来安装它们。它们将被上传到存储库。

回答by VdeX

Solution 1:

解决方案1:

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

您甚至可以在 D 盘或任何其他驱动器中创建新文件夹。并使用它。

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

不必使用默认创建的 .m2 文件夹。

Also change this to new path:

还将其更改为新路径:

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

Change setting as shown in image below:

更改设置,如下图所示:

Solution 2:

解决方案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

删除 .m2 文件夹,然后确保所有项目在 pom.xml 中只有新版本/所需版本的 jar 条目。重新构建项目。.m2 文件夹将只保留最新版本

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

提示:保持 IDE 和所需项目处于打开状态,以免被删除。

enter image description here

在此处输入图片说明

回答by Ralf Wagner

Maven downloads all dependencies to a folder .m2/repositoryin the user's home directory (i.e. C:\users\[your user name]\.m2\repositoryon Windows. When you delete this folder, Maven creates the folder and downloads the dependencies for the projects you're building from then on.

Maven 将所有依赖项下载到.m2/repository用户主目录中的一个文件夹(即C:\users\[your user name]\.m2\repository在 Windows 上。当您删除此文件夹时,Maven 会创建该文件夹并下载您正在构建的项目的依赖项)。

If you want to change the folder to another directory, you can put a Maven configuration file settings.xmlin the .m2directory. You can find a sample file in your Maven distribution in the confdirectory. Then look for the entry localRepositorywhich should be commented out like this:

如果要将文件夹更改为其他目录,可以settings.xml在该.m2目录中放置一个Maven 配置文件。您可以在 Maven 发行版中的conf目录中找到示例文件。然后查找localRepository应该像这样注释掉的条目:

<!-- localRepository
 | The path to the local repository maven will use to store artifacts.
 |
 | Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->

Activate it an set it to the path you like, e.g. make Maven download the dependencies to D:\myMavenRepositoryset it to

激活它并将其设置为您喜欢的路径,例如让 Maven 下载依赖项以D:\myMavenRepository将其设置为

<localRepository>D:/myMavenRepository</localRepository>

回答by honey reddy

Just open eclipse-->window-->preferences-->maven-->user settings-->in there see "local repository location". then find the location for your .m2/repository folder then delete that folder if your maven doesn't work properly.

只需打开 eclipse-->window-->preferences-->maven-->user settings--> 在那里看到“本地存储库位置”。然后找到您的 .m2/repository 文件夹的位置,如果您的 Maven 无法正常工作,请删除该文件夹。