如何解决maven循环依赖 [英] how to resolve maven cyclic dependency

查看:1687
本文介绍了如何解决maven循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何解决maven循环依赖,我们假设A是父项目,而B和C是子项目。如果B依赖于C,C依赖于B,是否有任何方法可以解决具有不同项目的循环依赖性。感谢提前,我已经在论坛搜索,但无法得到确切的解决方案。



请让我知道有没有可能。

解决方案

Maven不允许项目之间的循环依赖,因为否则不清楚要先建立哪个项目。所以你需要摆脱这个周期。一个解决方案是您已经提到的解决方案,以创建另一个项目。另一个是将某些类从B移动到C,反之亦然。或者有时如果不需要两个项目,将项目B和C合并到一个项目中是有道理的。



但是不知道和分析你的项目依赖的原因所以我建议你可以使用像 JDepend InteliJ 分析工具来查找有问题的课程,并根据他们找到一个更好的设计为您的软件。



大多数时候,我创建的东西像一个接口模块和实现模块,摆脱了大部分周期。


how can we resolve maven cyclic dependency, let us suppose A is the parent project and B and C are child projects. If B is dependent on C and C is dependent on B, is there any way to resolve the cyclic dependency other having a different project.

Thanks in advance, I have searched in the forums but could not get the exact solution. Please let me know if there is any possibility.

解决方案

Maven does not allow cyclic dependencies between projects, because otherwise it is not clear which project to build first. So you need to get rid of this cycle. One solution is the one you already mentioned, to create another project. Another one would be to just move some classes from B to C or vice versa when this helps. Or sometimes it is correct to merge project B and C to one project if there is no need to have two of them.

But without knowing and analyzing why your projects depend on each other it's kinda difficult to suggest the best solution.

So I suggest you can use tools like JDepend or the InteliJ analyse tool to find your problematic classes and based on them find a better design for your software.

Most of the time, I create something like an interface module and and implementation module, which gets rid of most cycles.

这篇关于如何解决maven循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆