为什么子项目无法识别依赖项?

时间:2019-09-18 18:40:59

标签: scala sbt

我已经定义了两个子项目,如下所示:

val Http4sVersion = "0.21.0-M4"
val CirceVersion = "0.12.1"
val Specs2Version = "4.7.0"
val LogbackVersion = "1.2.3"
val ScalaTestVersion = "3.0.8"
val TestContainerVersion = "1.11.3"
val KafkaTestContainerVersion = "1.11.3"
val ConfigVersion = "1.3.4"
val SpringVersion = "5.1.8.RELEASE"
val CatsVersion = "2.0.0"


lazy val settings = Seq(
  organization := "com.sweetsoft",
  name := "connector",
  scalaVersion := "2.13.0",
  addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
  addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0"),
  scalacOptions ++= Seq(
    "-deprecation",
    "-encoding", "UTF-8",
    "-language:higherKinds",
    "-language:postfixOps",
    "-feature",
    "-Xfatal-warnings",
  ),
  scalacOptions in(Compile, console) ~= {
    _.filterNot(Set("-Xlint"))
  }

)

lazy val dependencies = Seq(
  "org.http4s" %% "http4s-blaze-server" % Http4sVersion,
  "org.http4s" %% "http4s-blaze-client" % Http4sVersion,
  "org.http4s" %% "http4s-circe" % Http4sVersion,
  "org.http4s" %% "http4s-dsl" % Http4sVersion,
  "io.circe" %% "circe-generic" % CirceVersion,
  "ch.qos.logback" % "logback-classic" % LogbackVersion,
  "org.typelevel" %% "cats-core" % CatsVersion,
  "com.typesafe" % "config" % ConfigVersion % "test",
  "org.scalactic" %% "scalactic" % ScalaTestVersion % "test",
  "org.scalatest" %% "scalatest" % ScalaTestVersion % "test",
  "org.testcontainers" % "testcontainers" % TestContainerVersion % "test",
  "org.testcontainers" % "kafka" % KafkaTestContainerVersion % "test",
  "org.springframework" % "spring-core" % SpringVersion % "test",
  "org.typelevel" %% "cats-laws" % CatsVersion % "test",
  "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.3" % "test",
  "org.scalacheck" %% "scalacheck" % "1.14.0" % "test"
)



lazy val global = project
  .in(file("."))
  .settings(
    settings,
    libraryDependencies ++= dependencies
  )
  .aggregate(core, serversupervisor)


lazy val core = (project in file("core"))
  .settings(settings)


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

如您所见,两个子项目是core和serversupervisor。

问题是,这两个子项目无法识别依赖项:

enter image description here

我正在使用Intellj,如您所见,它无法识别依赖性。 我在做什么错了?

1 个答案:

答案 0 :(得分:3)

libraryDependencies ++= dependencies放入settings

globalcoreserversupervisor是三个不同的子项目。它们可以具有不同的库依赖关系。当前,您将它们添加到global,但没有添加到coreserversupervisor

或者,您可以将libraryDependencies ++= dependencies移至GlobalThisBuild范围,而不是特定的子项目范围。您可以在顶部添加

ThisBuild / libraryDependencies ++= dependencies

甚至

Global / libraryDependencies ++= dependencies

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

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