23

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

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.

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. Marry them and make them one maven project.
  2. Break their co-dependency

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

Any other solutions?

Lan
  • 1,127
  • 1
  • 10
  • 25
  • 9
    This made my day. – BackSlash Nov 21 '14 at 23:19
  • @BackSlash The instant downvote made my day. I wonder why. This is a serious question, I just phrased it allegorically. – Lan Nov 21 '14 at 23:20
  • It looks like you already know how to fix it. – rodrigoap Nov 21 '14 at 23:23
  • Actually, yes, despite the way this question is written it's a serious question. And it is written a very creative way IMO. Unfortunately I cannot help, I don't have a good enaugh knowledge of Maven, but I placed an upvote. Circular dependencies are evils. – BackSlash Nov 21 '14 at 23:23
  • 1
    Can you create and release to maven repository when they are not co-dependent and later each other depends on an older version of the other? – Gábor Bakos Nov 21 '14 at 23:26
  • @rodrigoap I'm humble and not omnipotent. I asked this question incase there is a better answer ("Oh, you didn't know run mvn with the blank flag") and because I may not be able to implement either of my solutions. – Lan Nov 21 '14 at 23:27
  • 2
    You could bootstrap it by depending on different versions, so you compile Alice1 which does not depend on Bob. Then you compile Bob1 depending on Alice1, and then you introduce Alice2, depending on Bob1. But not doing it is the best solution.) – eckes Nov 21 '14 at 23:28
  • You might give a try to build them together with the `-pl` switch of maven (http://stackoverflow.com/a/10719147). – Gábor Bakos Nov 21 '14 at 23:31
  • 2
    Maybe the solution is for Alice and Bob to have an affair. (I'd give you a serious answer if the question was written in a serious style.) – Stephen C Nov 21 '14 at 23:32
  • 2
    I would have said "that true POMantic" – Sangimed May 05 '17 at 12:52

1 Answers1

8

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.

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.

Makoto
  • 96,408
  • 24
  • 164
  • 210