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

Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project

程序员文章站 2022-06-01 15:29:16
...

我先说下我的打包步骤

一、复现

我的应用中有两个模块:client和common
其中client依赖common
Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project

打包步骤

先打包common,build success
再打包client,此时出错!错误信息如下

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< org.example:client >-------------------------
[INFO] Building client 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.309 s
[INFO] Finished at: 2020-06-17T16:58:00+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project client: Could not resolve dependencies for project org.example:client:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.example:common:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for org.example:common:jar:1.0-SNAPSHOT: Could not find artifact org.example:project-test:pom:1.0-SNAPSHOT -> [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

二、排查

上面错误信息中,有两行提示,我们摘出来

## 查看完整错误栈信息,可以添加-e 参数
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
## 查看完整的debug日志,可以添加-X 参数
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
1. 使用-e参数重新install

我们进入到client文件夹下,使用-e参数重新打包试试,看看它的异常栈信息

cd client
mvn clean install -e

Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project

2. 查看异常栈

异常栈很长查看最后一个即可,错误栈截图如下
Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project
清晰明了,打包异常的原因,就是因为没有找到org.example:project-test:pom:1.0-SNAPSHOT这个包!

三、解决

上面异常栈中org.example:project-test:pom:1.0-SNAPSHOT这个包,也就是子模块的父项目,即项目本身project-test。打包一下这个父项目,就能解决了。Maven打包错误:Failed to execute goal on project client: Could not resolve dependencies for project

结论

client打包时依赖common,而common依赖父工程project-test。
所以client先去本地查找project-test这个包;没找到就去私服中找,肯定还没找到;进而去*仓库查找,还是没找到,就报错了!

四、授之以渔

  1. 遇到打包错误的情况不要慌,直接加-X或者-e参数重新打包,看看错误日志是什么,一般都会显示很清楚的。
    -X 参数:显示打包过程中的debug日志
    -e 参数:显示完成错误栈信息
  2. 仔细看错误信息
    我们把最初的报错信息再摘出来一段:
    [ERROR] Failed to execute goal on project client: Could not resolve dependencies for project org.example:client:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.example:common:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for org.example:common:jar:1.0-SNAPSHOT: Could not find artifact org.example:project-test:pom:1.0-SNAPSHOT -> [Help 1]
    直接看最后一个错误,也能很清晰的看到提示缺少project-test:pom:1.0-SNAPSHOT这个包。