一场maven循环依赖引发的大案!

今儿个给应用jar包升级版本,哦豁,版本号升到高版本之后,开始编译的时候,编译不过去。

详细报错信息如下:

[ERROR] Failed to execute goal on project ton-search-api: Could not resolve dependencies for project com.*.hto:ton-search-api:jar:1.31.0-SNAPSHOT: Failure to find com.*.hto:ton-search-api:jar:1.31.0-SNAPSHOT in http://mvn.*-yun.com/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of dtdream 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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :ton-search-api


一开始以为是maven抽风了,所以直接打开网页搜索错误解决办法,找了很多都说【直接把本地仓库中的ton-search-api删除掉】。我试了好多次,都不行。

最后实在不行,只能从代码依赖关系屡一下:原来ton-search-api这个module是另一个同事添加的,该api依赖别的api,在这里叫ton-busib-api,而ton-busib-api又依赖了ton-search-api,两个api包相互依赖了。醉了醉了,本来api jar包要的就是轻便小巧,居然会发生api 依赖其他api 这种事,无疑加重了api包。非常不雅。然而这不是我关注的,我更关注问题如何解决。


果然在循环依赖的包引入的地方增加:

<exclusions>
    <exclusion>
        <groupId>com.*.hto</groupId>
        <artifactId>ton-search-api</artifactId>
    </exclusion>
</exclusions>

断掉循环依赖即可。



简单来说:又是一场循环依赖引发的大案。  A 包依赖了B包, B包依赖了A包,当A包版本从1.0.0升级到2.0.0的时候,A包在编译的时候,去远程仓库下载B包,发现B包依赖A包,遂继续在远程仓库下载A包2.0.0版本,结果maven傻了,就问A:兄弟,你自己的2.0.0 jar包不正在编译吗?你都还没编译成功,你怎么deploy?你没有deploy,你让我下载啥?你蒙我傻是不?我不干了。我抛错了。




循环依赖是指在Maven项目中,两个或多个模块之间相互依赖,形成一个闭环的依赖关系。这种情况下,Maven无法确定应该先构建哪个模块,因此会报错。 解决循环依赖问题有几种方案: 方案一是单依赖。可以删除其中一个模块对另一个模块的依赖,将依赖的业务迁移到另一个模块中。例如,在sso工程中删除对master-data工程的依赖,将依赖的业务迁移到sso工程中,或者在master-data工程中删除对sso工程的依赖,将依赖的部分迁移到master-data工程中。 方案二是使用插件build-helper-maven-plugin。可以添加一个中间模块,让两个模块都依赖于中间模块,而不直接相互依赖。这样可以规避循环依赖问题,但本质上循环依赖仍然存在。 另外,还有一种解决循环依赖的方法是修改pom.xml文件中的依赖。可以将循环依赖的模块的依赖范围(scope)修改为system,并指定systemPath为模块的jar包路径。这样可以解决循环依赖问题,但需要手动将依赖的jar包放置在指定路径下。 总结来说,解决Maven循环依赖问题的方法包括单依赖、使用插件build-helper-maven-plugin和修改依赖的范围和路径。具体选择哪种方法取决于项目的具体情况和需求。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [maven 循环依赖处理办法](https://blog.csdn.net/rootcn/article/details/99694157)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [解决maven循环依赖](https://blog.csdn.net/liouwb/article/details/123651961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长乐smile

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值