2

I have 2 projects and

+ proj1 has
    + com.myproj1 has
        + Runner.class
        + Logger.class

+ proj2 has
    + com.myproj2 has
        + Test.class
        + Fact.class

module com.myproj1 {
    requires module com.myproj2;
    exports com.myproj1
}

module com.myproj2 {
    exports com.myproj2;
    requires module com.myproj1;// the problem is "Cycle exists in module 
    dependencies, Module... "
}

I use Test.class from com.myproj2 in com.myproj1 Runner.class it is fine until here but when I try to use Logger.class in the Fact.class it gives me the problem "Cycle exists in module dependencies, Module ". I know modules are prevent to Cycle dependencies. But then what is the solution for the situations like this>

Jose Da Silva Gomes
  • 3,814
  • 3
  • 24
  • 34
James
  • 441
  • 2
  • 6
  • 9

1 Answers1

0

This is a false dependency loop because of how you structured your modules. Move Logger into its own module and import it in the other two projects. This is the general solution: factor out the dependency that is artificially causing the loop.

If you have a real circular dependency, you need to rearchitect the entire system to prevent it, but you do not have that situation here.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • Can you, please, elaborate your answer. I mean I'm still confused. When I read *module1 requires module2* **and** *module2 requires module1*, how come it is not cyclic dependency? – zlakad Mar 16 '18 at 04:19