Reputation: 2054
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
build.sbt
is much bigger than what you see above (dependencies, tasks etc.). Otherwise, I don't think if there's anything special or tricky about it.Help much appreciated!
Upvotes: 1
Views: 325
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
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