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

来源:互联网 发布:魔戒最后之日修改数据 编辑:程序博客网 时间:2024/04/28 18:14

今儿个给应用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,你让我下载啥?你蒙我傻是不?我不干了。我抛错了。