softshipper
softshipper

Reputation: 34081

Why subprojects does not recognize dependencies?

I've defined two sub projects that looks as follow:

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)

As you can see, the two subprojects are core and serversupervisor.

The problem is, that those two subprojects does not recognize dependencies:

enter image description here

I am using Intellj and as you can see, it does not recognize the dependencies. What am I doing wrong?

Upvotes: 0

Views: 54

Answers (1)

Dmytro Mitin
Dmytro Mitin

Reputation: 51683

Put libraryDependencies ++= dependencies into settings.

global, core and serversupervisor are three different subprojects. They can have different library dependencies. Currently you add them to global but not to core and serversupervisor.

Alternatively you can move libraryDependencies ++= dependencies to Global or ThisBuild scope rather than specific subproject scope. You can add at top

ThisBuild / libraryDependencies ++= dependencies

or even

Global / libraryDependencies ++= dependencies

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

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

Upvotes: 3

Related Questions