Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: cyclic dependence between modules?

Tags:

scala

sbt

Is it possible to have cyclic dependence between modules of a multi-module project?

Here is an example:

lazy val client = (project in file("client"))
  .dependsOn(service)
  .settings(...)

lazy val service = (project in file("service"))
  .dependsOn(client)
  .settings(...)

Im getting an error recursive value x needs type which I think is due to this recursive definition, but not completely sure (there might be some other weird phenomenon causing this).

like image 861
Daniel Avatar asked Jan 06 '23 05:01

Daniel


1 Answers

Why you ever need this? No build system provide support for cyclic dependencies, because its impossible to maintain correct build order in such case. If your module service depends on part of client, then you should move it out to a separate module (usually we call it common):

lazy val common = (project in file("common"))

lazy val client = (project in file("client"))
  .dependsOn(service, common)
  .settings(...)

lazy val service = (project in file("service"))
  .dependsOn(common)
  .settings(...)

Also, it's considered as a good practice to have separate sub-modules for service API and service implementation (service-api and service-impl). This way allows to decouple client from service implementation details

like image 67
Vitalii Kotliarenko Avatar answered Jan 08 '23 18:01

Vitalii Kotliarenko