总体
最近刚刚上手IDEA,下载插件时发现非常慢,发现主要是是配置的问题。
可以通过将下载源定义成阿里云镜像的方法解决。
步骤
1.找到如下文件
settings.xml
是 Maven 的全局配置文件,定义了 Maven 的全局设置,如镜像仓库、代理设置、本地仓库路径等。这个文件通常位于以下目录:
Windows: C:\Users\<你的用户名>\.m2\settings.xml
Linux 和 macOS: ~/.m2/settings.xml
2.自定义文件
如果找不到文件,在步骤一的路径下创建文件。注意创建时,先选择文本文档,再另存为.xml格式文件
3.定义如下XML配置
如果是已经有xml文件,添加如下代码即可:
<mirrors>
<mirror>
<id>aliyun-central</id>
<mirrorOf>central</mirrorOf>
<name>Aliyun Maven Central</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
</mirrors>
如果是自己新建的,则添加如下的完整代码:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>aliyun-central</id>
<mirrorOf>central</mirrorOf>
<name>Aliyun Maven Central</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings>
4.配置完成后
配置完成后,重新运行 Maven 构建命令,如 mvn clean install
,以使用新配置的镜像仓库。
总结
Windows 上操作,一般按以下步骤:
- 打开文件资源管理器,导航到
C:\Users\<你的用户名>\.m2
。 - 如果
settings.xml
文件不存在,右键选择 "新建" -> "文本文件",将其命名为settings.xml
,并确保文件扩展名为.xml
而不是.txt
。 - 打开
settings.xml
文件,将上述配置粘贴进去并保存。