Search code examples
scalasbtmulti-module

Cannot import classes from one module to other one - Scala


I have created a project with 3 different modules. First one is called http and second algebra. I have connected them into one in sbt file, but when I want to use classes from algebra in http then I cannot import them because they do not see each other. This is my sbt file:

lazy val commonSettings = Seq(
  libraryDependencies ++= Seq(
    "org.typelevel" %% "cats-core" % CatsVersion,
    "org.typelevel" %% "cats-effect" % "1.2.0",
    "org.typelevel" %% "cats-tagless-macros" % "0.2.0",
    "org.typelevel" %% "cats-mtl-core" % "0.5.0",
  )
)

lazy val root = project.in(file(".")).aggregate(http, domain, algebra)
  .settings(commonSettings)
  .settings(libraryDependencies ++= Seq(
    "org.tpolecat" %% "doobie-core" % DoobieVersion,
    "org.tpolecat" %% "doobie-h2" % DoobieVersion,
    "org.tpolecat" %% "doobie-scalatest" % DoobieVersion,
    "org.tpolecat" %% "doobie-hikari" % DoobieVersion,
  ))

lazy val http = (project in file("http"))
  .dependsOn(algebra)
  .settings(commonSettings)
  .settings(
    name := "my-http",
    libraryDependencies ++= Seq(
      "io.circe" %% "circe-generic" % CirceVersion,
      "io.circe" %% "circe-literal" % CirceVersion,
      "io.circe" %% "circe-generic-extras" % CirceVersion,
      "io.circe" %% "circe-parser" % CirceVersion,
      "io.circe" %% "circe-java8" % CirceVersion,
      "io.circe" %% "circe-config" % CirceConfigVersion,

      "org.http4s" %% "http4s-blaze-server" % Http4sVersion,
      "org.http4s" %% "http4s-circe" % Http4sVersion,
      "org.http4s" %% "http4s-dsl" % Http4sVersion,
    ))

lazy val domain = project.in(file("domain"))

lazy val algebra = (project in file("algebra"))
  .settings(commonSettings)
  .settings(
    name := "my-algebra",
  )

I tried to refresh all projects but it did not work.

class MyRoutes[F[_]: Effect](services: MyService[F]) extends Http4sDsl[F]{...}

Class MyRoutes is in http module and MyService in algebra module. The error is Cannot find declaration to go to on MyService. How can I fix it?


Solution

  • Ok, I solved this problem. It was my, stupid mistake. I have not marked directory as source root where is MyService. Because of this, in http module I could not see this class.