Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve cyclic dependency between different modules in a project in eclipse?

Tags:

java

eclipse

The Problem log in eclipse shows "A cycle was detected in the build path of the project ...." Any idea what to do to get rid of these cyclic dependencies? I don't know which projects are dependent on each other.

like image 596
Gaurav Pant Avatar asked Jun 20 '13 08:06

Gaurav Pant


People also ask

How can cyclic dependencies be resolved?

A cyclic dependency is an indication of a design or modeling problem in your software. Although you can construct your object graph by using property injection, you will ignore the root cause and add another problem: property injection causes Temporal Coupling. Instead, the solution is to look at the design closely.

How do I get rid of cyclic dependency in Java?

A simple way to break the cycle is by telling Spring to initialize one of the beans lazily. So, instead of fully initializing the bean, it will create a proxy to inject it into the other bean. The injected bean will only be fully created when it's first needed.

What is cyclic dependency impact of cyclic dependency on application?

Cyclic dependencies between components inhibit understanding, testing, and reuse (you need to understand both components to use either). This makes the system less maintainable because understanding the code is harder. Lack of understanding makes changes harder and more error-prone.

How does maven avoid cyclic dependency?

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.


2 Answers

You can adjust the circular dependencies severity in eclipse:

Preferences > Java > Compiler > Building > Build path problems > Circular dependencies
like image 99
JREN Avatar answered Sep 20 '22 15:09

JREN


There are three ways to remove cyclic dependency between projects in eclipse,

1.Go to project-> java compiler-> building -> Enable project specific settings.
Select build path problems and give warning as option for circular dependency.

2.Go to project->java build path. In projects tab, select the project and remove.

3.Go to your META-INF folder, open MANIFEST.MF. In your MANIFEST.MF view tab, you can see the cyclic dependent project in "Import package:" column.
Remove the project from the column.

The first option does not really resolve the error. The second and the third option are the right way to resolve this dependency.

like image 24
HareshKannan Avatar answered Sep 18 '22 15:09

HareshKannan