Higher-Kinded Type
Higher-Kinded Type

Reputation: 2054

sbt: Dependent project does not compile first

In my build.sbt (nothing fancy) ....

val common: Project =
  project
    .in(file("common"))
    .enablePlugins(...)
    .settings(libraryDependencies ++= ...)

val root =
project
      .in(file("."))
      .enablePlugins(...)
      .dependsOn(common)
      .aggregate(
        common,
        ....
      )
      .settings(...)

Problem

common does not compile before root, and so the compilation fails complaining that it cannot find those classes (in common)

FYI

Help much appreciated!

Upvotes: 1

Views: 325

Answers (2)

Eugene Yokota
Eugene Yokota

Reputation: 95604

I'd agree with Mario Galic on using lazy val. In fact, I'd recommend using lazy val at all times in build.sbt.

If there is a cycle, like common referring back to root, one technique you can use is to use LocalProject("project name"), like LocalProject("root"):

lazy val common = (project in file("common"))
  .settings(
    Test / test := (LocalProject("root") / Test / test).value
  )

Upvotes: 1

Mario Galic
Mario Galic

Reputation: 48410

To avoid initialisation problems try declaring projects as lazy vals

lazy val common = ...
lazy val root = ...

instead of strict vals

val common = ...
val root = ...

As a side note use dependsOn to establish ordering between subprojects, and not aggregate, because aggregate will not modify classpaths.

Upvotes: 2

Related Questions