无法将类从一个模块导入到另一个模块-Scala

时间:2019-03-17 13:38:52

标签: scala sbt multi-module

我创建了一个包含3个不同模块的项目。第一个称为http,第二个称为algebra。我已将它们连接到sbt文件中的一个文件中,但是当我想使用algebrahttp中的类时,则无法导入它们,因为它们彼此看不见。 这是我的sbt文件:

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",
  )

我试图刷新所有项目,但是没有用。

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

MyRoutes在http模块中,MyService在代数模块中。错误是Cannot find declaration to go to上的MyService。 我该如何解决?

1 个答案:

答案 0 :(得分:1)

好的,我解决了这个问题。这是我的愚蠢错误。我尚未将目录标记为MyService的源根目录。因此,在http模块中我看不到此类。