Maven 编译父子项目找不到父pom超级巨坑

异常信息:

[FATAL] Non-resolvable parent POM for xxxxx: Failure to transfer xxxxxx from xxxxxxxxxxxx was cached in the local repository, resolution will not be reattempted until the update interval of nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer artifact xxxxxxxxxx from/to nexus-snapshots (xxxxxxxxx): Transfer failed for xxxxxx 400 Repository version policy: SNAPSHOT does not allow version: 0.20.3 and 'parent.relativePath' points at wrong local POM @ line 5, column 13

网上看很多都把矛头指向parent.relativePath,这里异常提示的也是parent.relativePath问题,然后就会陷入怀疑人生的搜索和parent.relativePath相关的词条。

当然,首先检查的是parent.relativePath是否真的配错,如果parent.relativePath没有配错,并且gourpId,artifactId,version都没问题,同时,编译还会去远程仓库拉取父pom,笔者遇到的问题出现在一次修改groupId的过程中,所以远程仓库是找不到父pom的,这个时候就会怀疑人生了,按道理是优先从本地文件系统查找父pom,然后是local repository,最后是remote repository。这个时候自然想到的就是install父pom,但是,install的时候依然报了同样的错误,试了各种方法依旧不灵,最后偶然的发现报错的子pom数量并非等于所有的子pom数,于是,对比所有子pom的parent节点发现,version存在差异,没问题的version通过${version}引用的父pom中的properties,有问题的version直接写死的具体版本号,两种写法的具体version值是一致的,通过反复试验发现,结论是:子pom里面parent.version必须与父pom里面的version写法一致,笔者项目内的父pom version引用的${version},所有相同写法的子pom编译没问题。

posted on 2021-12-21 22:04  砌码匠人  阅读(6937)  评论(2编辑  收藏  举报

导航