问题描述
- Maven 打包失败,但开发环境可以看到 Jar 包。
- 提示
[WARNING] The POM for xxx is missing, no dependency information available
- 提示
Could not resolve dependencies for project yyy: Failure to find xxx in zzz was cached in the local repository
如图:
原因定位
新建小项目,仅包含问题 Jar 包,打包尝试
—— 问题依然存在。
删除本地 Repository ,包括 .m2(Windows) 和自定义的 localRepository。重新打包。
—— 问题依然存在。
因之前打包成功过,此次升级 Jar 包导致打包失败,故回顾最近改动。结果发现 Maven 的 setting.xml 配置了镜像,且镜像 URL 恰好与报错所显示一致。
故注释,并重新打包。
—— 成功。
解决方式
查看是否因配置文件配置了镜像,导致 pom.xml 中 repository 失效。若是,则可选择两种方式:
- 注释镜像配置
- 镜像 mirrorOf 排除包
如下:
<mirrors>
<!-- cdh in aliyun -->
<!--- 注释掉镜像,或者排除 xxx --->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!xxx</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<project ...>
...
<repositories>
<!--公司私服-->
<repository>
<id>xxx_nexus</id>
<name>xxx_nexus</name>
<url>http://maven.xxx.yyy/zzz/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>