【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies

项目结构图,如下:
【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第1张图片
今天给 cloud-consumer-hystrix-dashboard9001 打包的过程,遇到了一个意料之中的错误。

【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第2张图片

报错信息,如下:

[INFO] Scanning for projects…
[INFO]
[INFO] ----------< com.banana:cloud-consumer-hystrix-dashboard9001 >-----------
[INFO] Building cloud-consumer-hystrix-dashboard9001 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.022 s
[INFO] Finished at: 2021-10-09T15:56:54+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project cloud-consumer-hystrix-dashboard9001: Could not resolve dependencies for project com.banana:cloud-consumer-hystrix-dashboard9001:jar:1.0-SNAPSHOT: Failed to collect dependencies at com.banana:cloud-api-commons:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for com.banana:cloud-api-commons:jar:1.0-SNAPSHOT: Could not find artifact com.banana:cloud201230: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.

呦西,我懂了,我这就来操作一番。

首先进入模块所在的文件夹下。
【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第3张图片

执行以下命令看一下,是什么东西导致打包失败。

mvn clean install -e

【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第4张图片
可以看到,日志显示,缺少 cloud-api-commons:jar:1.0-SNAPSHOT

这个包,是我打包的模块引用的公共包。

哦,原来是这个原因,不多说,打包 cloud-api-commons 模块

不多说,直接 mvn package
【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第5张图片

可以看到,打包已经成功了

那么,接下来,我们开始打包 cloud-consumer-hystrix-dashboard9001 模块。

【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_第6张图片

结果又报错了,而且依然找不到 cloud-api-commons:jar:1.0-SNAPSHOT

不过,我发现了一个新的错误信息,就是这个
在这里插入图片描述
这是我父工程的pom,莫非要打包父工程?

抱着试试看的态度,先打包父工程,试一下子。

结果,你猜怎么着,嘿,问题解决了。

唯一让我难过的地方是,打包父工程的时候,它把我所有的子模块,统统打包了一遍。

可是,我只想打包子模块,不想打包其它的模块。

这可有点蛋疼阿。

总结

cloud-consumer-hystrix-dashboard9001打包时依赖 cloud-api-commons

cloud-api-commons 又依赖 父工程

所以 cloud-consumer-hystrix-dashboard9001 先去本地查找cloud-api-commons这个包

如果没找到就去私服中找,肯定找不到,然后再去中央仓库查找,还是没找到,就报错了!

后来,虽然将cloud-api-commons打包了,也找到了,但是cloud-api-commons需要依赖于 父工程

所以,归根结底,需要打包父工程

你可能感兴趣的:(踩过的坑,maven,jenkins,java)