我正在使用.sbt构建定义文件,并且我定义了许多共享相同版本号的相关依赖项,例如:
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",
...
)
我希望能够在一个地方指定版本号,就像你在Maven中用theitesites元素一样,即你可以在你的pom中指定以下内容:
<propeties>
<io.akka.version>2.0.3</io.akka.version>
</properties>
然后在声明依赖项时引用该属性:
<dependency>
...
<version>${io.akka.version}</version>
</dependency>
有人知道SBT中是否有类似的方法?
答案 0 :(得分:11)
如果您使用完整配置(.scala文件),只需编写普通的scala代码:
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",
...
)
对于.sbt配置,这看起来很相似,但不是那么优雅:
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",
...
)
}
答案 1 :(得分:5)
也许是这样的?
def akka(artifact: String) = "com.typesafe.akka" % ("akka-" + artifact) % "2.0.3"
libraryDependencies ++= Seq(akka("actor"), akka("slf4j"), akka("testkit") % "test" )