Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a SBT equivalent for Maven POM properties?

Tags:

scala

sbt

I'm using a .sbt build definition file and I have a number of related dependencies defined that share the same version number, e.g.:

libraryDependencies ++= Seq(
    "com.typesafe.akka" % "akka-actor" % "2.0.3",
    "com.typesafe.akka" % "akka-slf4j" % "2.0.3",
    ...
    "com.typesafe.akka" % "akka-testkit" % "2.0.3" % "test",
    ...
)

I would like to be able to specify the version number in one place, much like you could do in Maven with the properites element, i.e., you could specify the following in your pom:

<propeties>
    <io.akka.version>2.0.3</io.akka.version>
</properties>

and then reference that property later when declaring dependencies:

<dependency>
    ...
    <version>${io.akka.version}</version>
</dependency>

Does anybody know if there is a similar approach in SBT?

like image 807
Jonathan Avatar asked Sep 17 '12 13:09

Jonathan


2 Answers

If you're using full configuration (.scala file), just write plain scala code:

val ioAkkaVersion = "2.0.3"

libraryDependencies ++= Seq(
    "com.typesafe.akka" % "akka-actor" % ioAkkaVersion,
    "com.typesafe.akka" % "akka-slf4j" % ioAkkaVersion,
    ...
    "com.typesafe.akka" % "akka-testkit" % ioAkkaVersion % "test",
    ...
)

For .sbt configuration this will look similar, but not so elegant:

libraryDependencies ++= {
  val ioAkkaVersion = "2.0.3"
  Seq(
    "com.typesafe.akka" % "akka-actor" % ioAkkaVersion,
    "com.typesafe.akka" % "akka-slf4j" % ioAkkaVersion,
    ...
    "com.typesafe.akka" % "akka-testkit" % ioAkkaVersion % "test",
    ...
  )
}
like image 68
om-nom-nom Avatar answered Nov 18 '22 22:11

om-nom-nom


Perhaps something like this?

def akka(artifact: String) = "com.typesafe.akka" % ("akka-" + artifact) % "2.0.3"


libraryDependencies ++= Seq(akka("actor"), akka("slf4j"), akka("testkit") % "test" )
like image 5
Viktor Klang Avatar answered Nov 18 '22 23:11

Viktor Klang