问题

  在 pom 文件中加入了依赖,但 idea 并没有下载 jar 包,导致项目报错。

1、可能是 idea 没有配置 Maven

  打开 idea 的设置页面搜索 maven ,配置 maven 的地址、本地仓库、配置文件的位置。

image.png

image.png

2、网速慢,更换远程仓库

  maven 默认是从外网的远程仓库下载,下载速度不稳定。可以将远程仓库更换为阿里的远程仓库,提升下载速度。打开 maven 的配置文件 settings.xml,更改 mirrors 标签的信息。

  <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>
      <id>nexus-aliyun</id>
      <mirrorOf>central</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

3、刷新 pom 文件

  有时依赖包更新,需要重新引入,但是删掉旧包之后重新构建却无法自动下载新包,即使是重启 idea 也不会自动下载,可以尝试刷新 pom 文件。

image.png

4、使用命令刷新 pom 文件

  使用 mvn -U idea:idea 命令刷新。

image.png


标题:IDEA 中 Maven 依赖下载失败的解决方法
作者:Yi-Xing
地址:http://47.94.239.232:10014/articles/2020/03/09/1583761254172.html
博客中若有不恰当的地方,请您一定要告诉我。前路崎岖,望我们可以互相帮助,并肩前行!