1. 本地maven仓库有jar包,但是项目却从私服读取依赖
背景:将项目迁移到离线的电脑上进行开发,在读取依赖时,明明本地maven库有对应的jar包,但是项目却从私服读取,显示下载失败
报错信息:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< org.example:utils >--------------------------
[INFO] Building utils 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/tukaani/xz/1.9/xz-1.9.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.598 s
[INFO] Finished at: 2023-12-15T14:39:02+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project utils: Could not resolve dependencies for project org.example:utils:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.tukaani:xz:jar:1.9: Failed to read artifact descriptor for org.tukaani:xz:jar:1.9: Could not transfer artifact org.tukaani:xz:pom:1.9 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): maven.aliyun.com: Unknown host maven.aliyun.com -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] DependencyResolutionException - Apache Maven - Apache Software Foundation
检查过程如下:
1. 首先检查POM文件中的依赖配置是否正确,检查该依赖在本地库中是否已存在
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
<version>1.9</version>
</dependency>
2. 检查本地仓库的配置是否正确,即检查Maven的settings.xml文件中的localRepository元素,判断路径是否正确
<localRepository>E:\mvnwork</localRepository>
3. 修改对应依赖路径下的_remote.repositories文件
原本内容:
xz-1.9.jar>central=
xz-1.9.pom>central=
修改为:
xz-1.9.jar> =
xz-1.9.pom> =
然后重新加载依赖,成功加载。
或者可以直接将该文件删除。