Maven本地上有包还去网上找包

Maven本地上有包还去网上找包?

场景

  • 内网环境
  • 拿到一个本地库之后,进行编译,提示少包.
  • 从别的地方获取到包之后,放到本地库内后, 重新进行编译, 却还是少包
  • 在settings内设置了offline为true也没有用, 依旧找不到包

日志:

[ERROR] Plugin org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.springframework.boot:spring-boot-maven-plugin:jar:1.5.6.RELEASE: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.6.RELEASE from/to central (http://repo1.maven.org/maven2): repo1.maven.org: Name or service not known: Unknown host repo1.maven.org: Name or service not known -> [Help 1]

解决方法

删除本地库所有remote.repositories与lastUpdated

# cd 到本地库后, 
find -name "*remote.repositories" -or -name "*.lastUpdated" -type f |xargs rm -rf 

问题原因

在Maven读取本地库依赖的时候,会有一个验证Verifying availability过程.
而下载包的过程中

  • 如下载成功, 会生成_remote.repositories文件, 记录该包来源.
  • 如下载失败, 会生成.lastUpdated文件, 记录下载失败的链接库地址.

Verifying availability验证过程中如果发现依赖所在的文件夹内有以上文件, 则会进行对比, 如果对比结果有异则包验证失败.

posted @ 2021-10-29 14:28  Jrri  阅读(316)  评论(0编辑  收藏  举报