栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

解决idea打开的项目中maven依赖下载失败问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

解决idea打开的项目中maven依赖下载失败问题

​前期准备 1、设置idea的maven

步骤一,修改maven镜像地址

一般安装好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
		  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网站是一个道理。这样才会有修改镜像地址的操作,频繁切换下载源,总有一个能成功。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/733013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号