一般安装好maven后,都会先将maven镜像换为其他的镜像站,比如阿里云的镜像。因为网络的原因maven镜像会经常下载不成功,所有可以将maven安装目录下的conf文件下的setting.xml文件的mirrors节点中添加其他的镜像地址,具体镜像地址如下:
aliyun-maven-central central Human Readable Name for this Mirror. https://maven.aliyun.com/repository/central aliyun-maven-jcenter jcenter Human Readable Name for this Mirror. https://maven.aliyun.com/repository/jcenter aliyun-maven-public public Human Readable Name for this Mirror. https://maven.aliyun.com/repository/public aliyun-maven-gradle-plugin gradle-plugin Human Readable Name for this Mirror. https://maven.aliyun.com/repository/gradle-plugin aliyun-maven-spring spring Human Readable Name for this Mirror. https://maven.aliyun.com/repository/spring aliyun-maven-spring-plugin spring-plugin Human Readable Name for this Mirror. https://maven.aliyun.com/repository/spring-plugin aliyun-maven-grails-core grails-core Human Readable Name for this Mirror. https://maven.aliyun.com/repository/grails-core aliyun-maven-apache-snapshots apache-snapshots Human Readable Name for this Mirror. https://maven.aliyun.com/repository/apache-snapshots aliyun-maven-google Human Readable Name for this Mirror. https://maven.aliyun.com/repository/google repo2 central spring2.0 for this Mirror. https://repo.spring.io/libs-milestone net-cn central Human Readable Name for this Mirror. http://maven.net.cn/content/groups/public/ ui central Human Readable Name for this Mirror. http://uk.maven.org/maven2/ ibiblio central Human Readable Name for this Mirror. http://mirrors.ibiblio.org/pub/mirrors/maven2/ jboss-public-repository-group central JBoss Public Repository Group http://repository.jboss.org/nexus/content/groups/public
上方是绝大多数的镜像地址,看情况添加,一般情况下阿里云镜像已经够用了。
步骤二,更新将前两步完成后,执行下面的操作。
这时idea会到修改后的镜像地址下载依赖,好一点情况是,因为修改镜像地址下载依赖成功。但一般不会这么顺利的。
步骤三,删除下载失败的依赖因为依赖下载失败了,所以在本地仓库中往往会多了以 .lastUpdated为后缀的文件。找到这些文件,然后删除。
说白了就是频繁的修改setting.xml文件中的镜像地址来下载依赖,不停的切换下载源(可以在官方镜像和阿里云镜像之间进行切换,步骤一中提供了许多的镜像地址都可以进行尝试),每次切换镜像前,删除下载失败的依赖。一直重复步骤一到步骤三的操作,直到成功。
前面三个步骤,说实话已经可以解决99%的情况了,但凡事不能说的太满,还是会有意外情况的。
意外情况一般会出现这样的情况,不管如何切换镜像地址,依赖死活下载不成功,得到的永远是以 .lastUpdated为后缀的文件。这时就只能自己去网上手动下载了,一般情况下都是下载.pom文件,因为某个pom文件下载失败就会导致下面与这个依赖相关的文件都无法下载。
下面以spring-boot-starter-2.3.9.RELEASE.pom.lastUpdated为例子,如何在网上下载呢?
阿里云镜像 Maven镜像
把下载好的文件放在本地仓库中对应的目录下,你会发现依赖又可以正常下载了,再重复前面的三个步骤。
总结其实依赖下载不了的大多数原因就是网络的问题,因为有些仓库的服务器是在国外的,在国内访问那些服务器来下载依赖本身就存在着很大的延迟,所有才会下载失败。就跟访问GitHub网站是一个道理。这样才会有修改镜像地址的操作,频繁切换下载源,总有一个能成功。



