方法一:修改maven配置文件
我使用的是IDEA编译器,使用maven自己的库下载文件非常的慢。阿里代理了很多公共的maven仓库,使用maven.aliyun.com中的仓库地址作为下载源,速度更快更稳定。
打开你的maven的安装地址,找到conf文件夹下面的settings.xml文件并打开,在<mirrors></mirrors>标签中间插入镜像的配置参数。
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>central库</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
如果需要替换的话,将URL中的地址替换为下表中的Path列所对应的url。
Repository | Type | Policy | Path |
apache snapshots | proxy | SNAPSHOT | https://maven.aliyun.com/repository/apache-snapshots |
central | proxy | RELEASE | https://maven.aliyun.com/repository/central |
| proxy | RELEASE | https://maven.aliyun.com/repository/google |
gradle-plugin | proxy | RELEASE | https://maven.aliyun.com/repository/gradle-plugin |
jcenter | proxy | RELEASE | https://maven.aliyun.com/repository/jcenter |
spring | proxy | RELEASE | https://maven.aliyun.com/repository/spring |
spring-plugin | proxy | RELEASE | https://maven.aliyun.com/repository/spring-plugin |
public | group | RELEASE | https://maven.aliyun.com/repository/public |
releases | hosted | RELEASE | https://maven.aliyun.com/repository/releases |
snapshots | hosted | SNAPSHOT | https://maven.aliyun.com/repository/snapshots |
grails-core | proxy | RELEASE | https://maven.aliyun.com/repository/grails-core |
mapr-public | proxy | RELEASE | https://maven.aliyun.com/repository/mapr-public |
保存并重启编译器即可。
方法二:修改项目的pom.xml文件
打开你的项目,找到pom.xml文件,在<repositories></repositories>中添加<repository></repository>仓库,格式如下。仓库的地址同第一种方法中的仓库地址。
<repositories>
<repository>
<id>maven-ali</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>