Maven 打包失败,提示 “POM for xxx is missing, no dependency information available“

问题描述

  1. Maven 打包失败,但开发环境可以看到 Jar 包。
  2. 提示 [WARNING] The POM for xxx is missing, no dependency information available
  3. 提示 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 失效。若是,则可选择两种方式:

  1. 注释镜像配置
  2. 镜像 mirrorOf 排除包

    如下:

setting.xml

  <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>

pom.xml

<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>

猜你喜欢

转载自blog.csdn.net/xiaolegeaizy/article/details/111356120