Search code examples
javaeclipsemavencircular-dependency

How to solve a cyclic project dependency in Eclipse. Any way to make one of the dependencies runtime only?


I have a project that basically consists of 2 modules. I have a Eclipse workspace and 2 java projects (maven) in it which represent those two modules.

To go a bit more in depth:

  • Project 1: Core Module (Has Core Implementation and API Interfaces)
  • Project 2: Auxiliary Module (A Server)

Project 2 requires to have Project 1 as Dependency in order to access the API Interfaces during compile time. But the problem is that Project 1 requires Project 2 in order to work properly (This is only a runtime requirement though).

So when I add in each project the other project as dependency a cyclic dependency error is shown, as Eclipse doesn't knows in which order to compile the classes.

The way I managed to make this work is that I added the "bin" folder from Project 2 as dependency to Project 1 as also all of Project 2 dependencies (Which are maven based). This though makes the whole project completely bound to my system, as all paths are adjusted to my computer setup.

Is there any proper way to specify another project to be dependency only on "runtime", and not on "compile" and avoid the cyclic redundancy in Eclipse?


To explain in a more visual way. What I need is:

  • Project 2 --- During compilation depends on ---> Project 1

  • Project 1 --- During runtime depends on ---> Project 2


Solution

  • Eclipse can handle circular project dependencies but by default circular dependencies will be reported as an error for good reasons (splitting code into projects with circular dependencies makes no sense).

    You can decrease the circular dependencies project problem severity from Error to Warning for both projects as follows (not recommended):

    1. In Project > Properties: Java Compiler > Building
      1. check the checkbox Enable project specific settings and
      2. in the section Build path problems choose for Circular dependencies Warning instead of Error