My project setup looks somewhat like this:
Project: root (build.sbt
, version.sbt
)
Sub-project: projectA (build.sbt
)
Sub-project: projectB (build.sbt
)
In my version.sbt
I have a val
that reads the version to use from an external json file like this:
version in ThisBuild := findVersion
lazy val findVersion: String =
parse(Source.fromFile("../buildProperties.json").mkString).map(_ \\ "version").map(_ map (_.asString)) match {
case Right(Some(x) :: _) => x
case _ => throw new IllegalArgumentException("Unable to read buildProperties.json")
}
I now need to use this version to define dependencies inside the subprojects (projectA & projectB). So I either:
val findVersion
of the root project from within
the build.sbt
of projectA & projectB OR libraryDependencies += "ext-lib" % "com.fbaierl" % version.value % Provided
. But this results in a error: 'value' can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting.
exception.Is there any way I can achieve what I need?
The recommended way of depending between projects would be in your root / build.sbt have something like this
val projectA = project in file("projectA")
val projectB = (project in file("projectB")).dependsOn(projectA)
If that is not what you have / need, then you can use the version task to set versions in setting dependecies like so:
libraryDependencies := { libraryDependencies.value :+ ("ext-lib" %% "com.fbaierl" % version.value) }
Hope that helps