Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题

IDEA 使用Maven开发过程中遇到两种问题:

1、 IDEA上使用maven插件,在pom.xml编写项目依赖的jar包时,已经下载到本地的jar,无法自动补全,需要手动书写。

2、代码编写过程中,写新的类但是没有在pom.xml中添加依赖,可以ALT+Enter组合件选择 Add Maven Dependency (添加maven依赖)

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第1张图片

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第2张图片

发现搜索的结果总是为空 (No results)


有两种方案:一种是曲线救国直接从中央库搜索复制对应配置;还有一种方式是通过更新中央库索引。


第一种方案:

这也有一个曲线救国的方案直接在  maven仓库中搜索:https://mvnrepository.com 并复制对应的依赖配置。

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第3张图片


Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第4张图片


直接复制就可以在pom.xml里面粘贴

第二种方案:

在settings ->Build ->Build Tools-->Maven -->Repositories 

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第5张图片

没有更新过的Updated对应的值为Never

点击右侧的Update按钮


Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第6张图片

等待更新完成(时间较长,需要耐心等待,也可以使用代理),完成后会Processing indices(处理索引)

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第7张图片

然后更新本地仓库

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第8张图片

等更新以后,核对一下是否更新成功

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第9张图片

这里应该有对应的更新日期,如果这一行显示的是粉红色,可以看到对应的原因,如:


那么需要在setting.xml中或者IDEA中设置代理

Maven依赖就可以自动提示补全了

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第10张图片

如果还没有添加依赖也可以使用IDEA来搜索和添加maven依赖了。

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第11张图片

Intellij IDEA Maven dependency自动补全和Maven Artifact Search为空问题_第12张图片


你可能感兴趣的:(Java基础)