在Maven中解析或编译循环依赖 [英] Resolving or Compiling Circular Dependency in Maven

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

问题描述

我有一个有趣的问题,而不是寻找 解决方案,我正在寻找解决方案 s

I have a bit of a funny problem and instead of looking for a solution to it, I'm looking for solutions.

Project Alice有一个pom.xml。在它里面,pom说她被打包成一个罐子,虽然她是一个坚强的女人,但她依赖鲍勃。项目鲍勃,作为一个补充,说他依赖爱丽丝。因为循环依赖。

Project Alice has a pom.xml. In it the pom says she gets packaged as a jar and although she is a strong woman, she is dependent on Bob. Project Bob, being a complementarian, says he depends on Alice. Ergo a circular dependency.

当然,在Alice上运行 mvn compile 说Alice正在失踪Bob。鲍勃,真正的浪漫,如果你试着编译他,他也会想念爱丽丝。

Of course, running mvn compile on Alice says "Alice is missing Bob". And Bob, that true romantic, if you try and compile him, he misses Alice too.

既然没有其他礼物就不会遵守,我正在寻找方法来解决这个问题。

Since neither will comply without the other present, I'm looking for ways to resolve this.

我只知道如何解决这个问题的方法:

There is only two ways I know how to resolve this:


  1. 嫁给他们并让他们成为一个maven项目。

  2. 打破他们的共同依赖

除了我不想宣传乱伦之外,还会制作父母pom并让Alice和Bob兄弟姐妹解决这个问题吗?

Besides the fact that I don't want to promote incest, would making a parent pom and making Alice and Bob siblings solve this?

任何其他解决方案 s

推荐答案

弄清楚Alice和Bob彼此迫切需要的是什么并介绍 - 让我们称之为查理 - 作为自己独立的POM。然后,让Alice和Bob依赖查理。

Figure out what it is that Alice and Bob desperately need from each other, and introduce that - let's call it Charlie - as its own separate POM. Then, have Alice and Bob depend on Charlie.

这里要注意的重要一点是循环依赖性通常是由于某些模块包含的内容超出了它的需要。鉴于Alice需要Bob和Bob需要Alice,有些东西可以从这两个模块中分离出来并作为第三个模块引入。

The big thing to note here is that circular dependencies arise often due to certain modules encompassing more than it needs to. Given that Alice needs Bob and Bob needs Alice, there is something that could be split off from within those two modules and introduced as a third one.

这可能不是大多数有吸引力的解决方案,但它是最干净的。然后,您将更多模块化引入系统,并为模块重构提供更多机会。

This is probably not the most attractive solution, but it's the cleanest. You then introduce more modularity into your system, and some more opportunities for module refactoring.

这篇关于在Maven中解析或编译循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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