解决IDEA中Maven下载依赖包过慢或报错的问题

 由于公司项目迭代,越来越多的项目开始转型新版本,由于我对Java一直不感冒,但要顺应公司项目要求,遂自己要逐步开始完善Java相关的知识层面,此篇是我在学习SpringBoot时对一些不懂地方及遇到问题时的记录。

学习视频链接:

B站-黑马程序员-SpringBoot篇icon-default.png?t=N7T8https://www.bilibili.com/video/BV1Lq4y1J77x/?spm_id_from=333.337.search-card.all.click

在初步建立好项目后,Maven在下载依赖,等了很久,始终有4个依赖报错,通过网上查询,找到了解决方案:

问题原因:导致IDEA Maven下载依赖包速度过慢,有很大一部分原因是因为需要请求到国外镜像仓库,响应比较慢,遂会造成等待时间久、相应报错的问题。

解决方案:

1.鼠标右击自己的项目,找到【Maven】

2.选择【Open ‘settings.xml'】或者【Create ‘settings.xml’】

3.将以下代码粘入文件中,重启IDEA后即可提高速度

【设置Maven镜像库为阿里云镜像库和Junit镜像库】

<?xml version="1.0" encoding="UTF-8"?>
<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>mirrorId</id>-->
<!--      <mirrorOf>repositoryId</mirrorOf>-->
<!--      <name>Human Readable Name for this Mirror.</name>-->
<!--      <url>http://my.repository.com/repo/path</url>-->
<!--    </mirror>-->
 
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
 
    <mirror>
        <id>uk</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://uk.maven.org/maven2/</url>
    </mirror>
 
    <mirror>
        <id>CN</id>
        <name>OSChina Central</name>
        <url>http://maven.oschina.net/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
 
    <mirror>
        <id>nexus</id>
        <name>internal nexus repository</name>
        <url>http://repo.maven.apache.org/maven2</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
 
    <!-- junit镜像地址 -->
    <mirror>
        <id>junit</id>
        <name>junit Address/</name>
        <url>http://jcenter.bintray.com/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
 
<!--    <mirrors>-->
        <!-- mirror
         | Specifies a repository mirror site to use instead of a given repository. The repository that
         | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
         | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
         |
        <mirror>
          <id>mirrorId</id>
          <mirrorOf>repositoryId</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>http://my.repository.com/repo/path</url>
        </mirror>
         -->
 
        <mirror>
            <!--This sends everything else to /public -->
            <id>nexus-aliyun</id>
            <mirrorOf>*</mirrorOf>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
 
        <mirror>
            <id>osc</id>
            <mirrorOf>*</mirrorOf>
            <url>http://maven.oschina.net/content/groups/public/</url>
        </mirror>
 
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
 
        <mirror>
            <id>net-cn</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://maven.net.cn/content/groups/public/</url>
        </mirror>
 
        <mirror>
            <id>ui</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://uk.maven.org/maven2/</url>
        </mirror>
 
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
 
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
 
        <mirror>
            <id>JBossJBPM</id>
            <mirrorOf>central</mirrorOf>
            <name>JBossJBPM Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
        </mirror>
 
    </mirrors>
</settings>
 

截止到此,Maven的依赖包就能很快速的下载了。

另一种解决方案

1.设置Maven镜像仓库

在Maven文件夹下找到【conf】文件夹下,找到【setting,xml】,编辑此文件,如果里面已经配置了阿里云镜像库和Junit镜像库则跳过,如果没有则进行插入。

2.编辑【setting】

学习参考网址

方案一

方案二

  • 15
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清晨的风Tank

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值