bertvh
bertvh

Reputation: 831

What place for shared dependency versions in multi-module build?

I have a multi-module SBT project where several of the subprojects depend on the same artifacts. I would like to manage the versions of these common dependencies at the root project so that I can do something like this in the subprojects (global.SprayVersion should come from the root project):

libraryDependencies += "io.spray" % "spray-client" % global.SprayVersion

What I've tried:

Should I define new SettingKeys for each dependency? This seems a bit overkill to me. I would like to keep a bit more grouped, not polluting the setting key namespace. Also, the subprojects don't need to be able to override these values.

Upvotes: 1

Views: 1034

Answers (1)

Vladimir Matveev
Vladimir Matveev

Reputation: 127751

You can define a sequence of dependencies, for example, in a separate object, like this:

object Deps {
  val akka = Seq(
    "com.typesafe.akka" %% "akka-actor" % Global.akkaVersion,
    "com.typesafe.akka" %% "akka-slf4j" % Global.akkaVersion
    "com.typesafe.akka" %% "akka-testkit" % Global.akkaVersion % "test"
  )
}

where Global is just an object with a number of strings in it:

object Global {
  val akkaVersion = "2.2.4"
}

Then you can just use Deps contents in your subprojects:

val project1 = Project(...)
  .settings(libraryDependencies ++= Deps.akka)

val project2 = Project(...)
  .settings(libraryDependencies ++= Deps.akka)

Upvotes: 3

Related Questions