tytk
tytk

Reputation: 2332

Is there any way to get around circular dependencies in Maven modules?

I have two modules in my package, call them Module1 and Module2. Module1 has a dependency on Module2 and would prefer to leave this alone (part of legacy code that I don't want to break).

There is a class that is part of Module1 that I need to use in Module2 - call it Class1. There are a couple wrapper objects around it and I don't care if they live in Module1 or Module2. The problem is Module1 already depends on Module2 so I can't add a dependency for Module2 on Module1. Is there any way at all to access Class1 inside Module2? I suspect not but I'm not sure how to go about designing this feature without the dependencies in this direction (I've been thinking about interfaces, factories and adding a third module).

Any tips on designing so that this doesn't happen? If it matters, this is a Java/Groovy project.

Upvotes: 1

Views: 629

Answers (1)

Vaibhav
Vaibhav

Reputation: 881

If you are having cyclic dependency in your projects, it is basically due to bad design or issue in logical grouping of classes.

You can create new project and merge classes from both modules in it, if they are logically/functionally related to each other. You can use InteliJ analyse tool to find such cyclic dependent classes and improve your design.

Upvotes: 1

Related Questions