0

I've three separeted git projects, with SBT. They depends on each other, I'm having bad headaches hopping from one to another when looking at call stack. I wanted to group them under a single sbt project, using git submodules, so I've created a module for each one and then a build.sbt in father project. ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.12.16"

lazy val core = RootProject (file("core"))
lazy val plugins = RootProject (file("plugins"))
lazy val utilities = RootProject (file("utils"))
lazy val root = (project in file("."))
  .dependsOn(core, plugins, utilities)
  .settings(
    name := "aggregator"
  )

But I've got an error: java.lang.NoClassDefFoundError: okhttp3/Interceptor,

I feel that is the wrong way to do it, anyone has some example on how it should be done? I need only to navigate the code easily, I don't care if single module will not produce the fat jar.

D. belvedere
  • 45
  • 2
  • 8
  • https://stackoverflow.com/questions/36762532/sbt-cyclic-dependence-between-modules https://stackoverflow.com/questions/54084642/circular-project-dependencies-with-a-testkit-sbt https://stackoverflow.com/questions/37037550/circular-dependency-in-scala https://www.scala-sbt.org/1.x/docs/Multi-Project.html https://stackoverflow.com/questions/25558234/are-cyclic-dependencies-supported-in-sbt https://stackoverflow.com/questions/44764692/cyclic-dependencies-between-main-test-modules-in-sbt https://stackoverflow.com/questions/38907340/ https://stackoverflow.com/questions/45220060 – Dmytro Mitin Mar 15 '23 at 19:03
  • It's not clear what you did so that you have `NoClassDefFoundError` – Dmytro Mitin Mar 15 '23 at 19:04
  • 1
    I'm not giving particular attention to error, beacause I'm not sure that I'm on the right path to achieve what I want. I want to aggregate three project as described, core and plugins depends on utilities. Sorry for the lack of details but I'm not used to SBT, on Maven it was so simple, the only things to do was make a father pom that includes other modules – D. belvedere Mar 15 '23 at 19:13
  • You could add to your question `pom.xml`s that everything worked as you want with them – Dmytro Mitin Mar 15 '23 at 19:18
  • *"They depends on each other"* This is not clear. What depends on what (out of `core`, `plugins`, `utilities`)? Or does everything depend on everything (it's bad, sbt doesn't support subprojects depending on each other cyclically)? Normally you need `project.settings(...).dependsOn(...)`. In complicated cases maybe subprojects can be published locally (`sbt publishLocal`) and used as library dependencies, not subprojects. – Dmytro Mitin Mar 15 '23 at 19:24
  • By the way, Maven doesn't allow cyclic dependencies between subprojects either https://stackoverflow.com/questions/16468525/how-to-resolve-cyclic-dependency-in-maven – Dmytro Mitin Mar 15 '23 at 19:37
  • https://www.scala-sbt.org/1.x/docs/Multi-Project.html#Appendix%3A+Subproject+build+definition+files *"Style choices: 1) Each subproject’s settings can go into `*.sbt` files in the base directory of that project, while the root `build.sbt` declares only minimum project declarations in the form of `lazy val foo = (project in file("foo"))` without the settings. 2) We recommend putting all project declarations and settings in the root `build.sbt` file in order to keep all build definition under a single file. However, it’s up to you."* – Dmytro Mitin Mar 15 '23 at 19:41
  • Why is it important that subprojects are git submodules? I guess this is important for git, not for sbt. – Dmytro Mitin Mar 15 '23 at 19:43

1 Answers1

0

core and plugins depends on utilities

Try to have the only build.sbt at the root

lazy val core = (project in file("core"))
  .dependsOn(utilities)

lazy val plugins = (project in file("plugins"))
  .dependsOn(utilities)

lazy val utilities = (project in file("utilities"))
 
lazy val root = (project in file("."))
  .settings(
    name := "aggregator"
  )
  .aggregate(core, plugins, utilities)

which is almost the same (except the name aggregator) as

lazy val core = (project in file("core"))
  .dependsOn(utilities)

lazy val plugins = (project in file("plugins"))
  .dependsOn(utilities)

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

(root is implicitly created if not defined)

https://www.scala-sbt.org/1.x/docs/Multi-Project.html

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • I've already tried that following this link, I've got errors on Imports in build.sbt , like on this one that exists in every subproject: import com.gilcloud.sbt.gitlab.GitlabCredentials – D. belvedere Mar 16 '23 at 15:34
  • @D.belvedere Most probably you didn't add some library dependency to `project/build.sbt` (do not confuse wth root `build.sbt`) or sbt plugin to `project/plugins.sbt` i.e. to the metaproject, i.e. the project building the main project ([sbt is recursive](https://www.scala-sbt.org/1.x/docs/Organizing-Build.html#sbt+is+recursive)). If you need more help please prepare some reproduction (original `pom.xml`s, current `build.sbt` etc.). – Dmytro Mitin Mar 16 '23 at 15:59