Maven 项目中,“Dependency ‘xxxx‘ not found“ 解决过程
Maven项目中,"Dependency 'xxxx' not found" 解决过程
问题
在使用 IDEA
开发过程中,添加了一个 jar
包的依赖,突然发现版本号是红色,移动鼠标上去后提示 Dependency xxxx not found
。去 maven
仓库中可以找到此 jar
包。为什么它不自动下载呢?
解决方法
经过了解后,发现跟我本地 maven 文件夹中的 setting.xml
配置有些关系。
setting.xml 文件
假如,你设置了 aliyun
镜像代理,如下:
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<!-- *表示所有的仓库只使用aliyun的镜像,实际是aliyun只镜像了central,所以这里要写成写成central -->
<!--<mirrorOf>*</mirrorOf>-->
<mirrorOf>central</mirrorOf>
</mirror>
我们在 maven repository
仓库中查找 HTTP Kit
包得到如下信息:
我们可以看到此包的 repository
是 Clojars
。它表示这个 jar
包在 Clojars
仓库中。而不是在常见的 central
仓库中。那么我们使用上面的 aliyun
镜像就会出现问题。因为 aliyun
镜像只镜像了 central
仓库。
所以,知道问题了,那我们再给他把 Clojars
仓库配置进去就可以了。这里以 JBoss
仓库为例。
<mirror>
<id>jboss</id>
<name>jboss</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
<mirrorOf>JBoss Releases</mirrorOf>
</mirror>
pom.xml 文件
另一种方法是在 pom.xml
直接添加额外的仓库。
<repositories>
<repository>
<id>JBoss repository</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</repository>
</repositories>