欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mvn build 报错 [ERROR] Failed to execute goal on project demo: Could not resolve dependencies

程序员文章站 2022-04-28 09:24:35
...

Java springboot 项目执行 mvn clean package -Dmaven.test.skip=true

报错

Downloaded from my-nexus: http://192.168.43.11:8081/nexus/repository/maven-public/org/springframework/spring-test/5.2.5.RELEASE/spring-test-5.2.5.RELEASE.jar (685 kB at 11 kB/s)
Downloaded from my-nexus: http://192.168.43.11:8081/nexus/repository/maven-public/org/assertj/assertj-core/3.13.2/assertj-core-3.13.2.jar (4.5 MB at 70 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:05 min
[INFO] Finished at: 2020-04-02T08:32:12Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project com.example:demo:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.jayway.jsonpath:json-path:jar:2.4.0, net.minidev:json-smart:jar:2.3, net.minidev:accessors-smart:jar:1.2, jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3, jakarta.activation:jakarta.activation-api:jar:1.2.2: Failure to find com.jayway.jsonpath:json-path:jar:2.4.0 in http://192.168.43.11:8081/nexus/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of my-nexus has elapsed or updates are forced -> [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] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

一开始以为是依赖包没有下载下来,查看本地的仓库,发现包都是存在的,仔细看报错信息Could not resolve dependencies指的是无法解析依赖包,难道是下的包不完整?
将本地包的大小和实际的相比较,发现果然是小很多。

try1

删除本地相关的包,重新执行mvn clean package -Dmaven.test.skip=true,然并卵,重试两三次都不行!!!

突然想到是不是私有仓库到*仓库下载的包就是损坏的(我的maven setting.xml文件配置的是从私有仓库nuxes获取包)

接着登录私有nexus私有仓库,检查发现nexus配置的是直接从*仓库https://repo1.maven.org/maven2/拉取的包,并没有配置国内的镜像,这就可能导致在下载的包不完整

try2

step1:给nexus配上aliyun仓库,参考(或自行百度)

https://blog.csdn.net/lishuoboy/article/details/99946230

step2:根据报错中列出无法解析的包,删除本地和nexus仓库中损坏的包(注意不要删错了公司内部的)
step3: 重新执行编译命令,我这里是mvn clean package -Dmaven.test.skip=true

ojbk

Downloaded from my-nexus: http://192.168.43.11:8081/nexus/repository/maven-public/org/ow2/asm/asm-util/7.2-beta/asm-util-7.2-beta.jar (81 kB at 2.6 kB/s)
Downloaded from my-nexus: http://192.168.43.11:8081/nexus/repository/maven-public/org/vafer/jdependency/2.3.0/jdependency-2.3.0.jar (169 kB at 5.1 kB/s)
Downloaded from my-nexus: http://192.168.43.11:8081/nexus/repository/maven-public/com/google/guava/guava/19.0/guava-19.0.jar (2.3 MB at 55 kB/s)
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  07:24 min
[INFO] Finished at: 2020-04-02T08:45:04Z
[INFO] ------------------------------------------------------------------------

总结

遇到这种问题,首先检查本地仓库的包是否完整的,有时候可能是自己网络的问题,导致拉的包是损坏的,有时可能时私服上的包就是损坏的,要逐步排查

相关标签: java 开发