[英]Handling interdependencies in maven multi-module project
I'm been going through the Maven Framework
.我一直在浏览
Maven Framework
。 While going through multi-module projects, I read that cyclic dependency is not acceptable among the modules.在进行多模块项目时,我读到模块之间不能接受循环依赖。 So I thought of a scenario, something like...
所以我想到了一个场景,比如……
root ----------
- pom.xml |
|
|--- moduleA
| - pom.xml (moduleB has been added as a dependancy)
|
|--- moduleB
- pom.xml
Assume that moduleA
has a property class AppProperty
and a Main
class which invokes another class B
available in moduleB
假设
moduleA
有一个属性类AppProperty
和一个调用moduleB
可用的另一个类B
的Main
类
Main
class available in moduleA
:- Main
可用类moduleA
: -
someValue = AppProperty.get(propKey);
//some logic
B mb = new B();
B.process(...);
Class B
of moduleB
:- moduleB
B
类:-
process(...) {
someOtherValue = AppProperty.get(someKey)
// some other logic
}
Now Main
will not throw any compile-time errors
as its dependancies have been resolved because moduleB
has been added as a dependancy in moduleA'a pom.xml
.现在
Main
不会抛出任何compile-time errors
因为它的依赖项已经解决,因为moduleB
已作为依赖项添加到moduleA'a pom.xml
。 But for class B
that is not the case as its invoking AppProperty
class which is available in moduleA
only.但是对于
B
类,情况并非如此,因为它的调用AppProperty
类仅在moduleA
可用。 I cannot add moduleA
's dependancy in moduleB
's pom as that would lead to cyclic dependancy (if I understand it correctly).我不能在
moduleB
的 pom 中添加moduleA
的依赖,因为这会导致循环依赖(如果我理解正确的话)。
I understand that ideally it is advised to maintain codes in an acyclic manner, but what if because of some reason removing cyclic dependancy is just not feasible?我理解理想情况下建议以非循环方式维护代码,但是如果由于某种原因消除循环依赖是不可行的怎么办? In such a scenario, is there any way to handle cyclic dependancies without actively changing the existing code logic ?
在这种情况下,有没有办法在不主动改变现有代码逻辑的情况下处理循环依赖?
You cannot build a project with cyclic dependencies.您不能构建具有循环依赖项的项目。 You need to build B before A before B, which is kind of a contradiction.
您需要在 B 之前先构建 B,这有点矛盾。
But problems like yours are easy to solve:但是像你这样的问题很容易解决:
AppProperty
or a few others, just move them from A to B.AppProperty
或其他几个,只需将它们从 A 移到 B。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.