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?
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",
...
)
}
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" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With