我使用的是.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中使用properites元素一样,也就是说,您可以在pom中指定以下内容:
<propeties>
<io.akka.version>2.0.3</io.akka.version>
</properties>然后在声明依赖关系时引用该属性:
<dependency>
...
<version>${io.akka.version}</version>
</dependency>有人知道SBT中是否有类似的方法吗?
发布于 2012-09-17 21:45:17
如果您使用的是完整配置(.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",
...
)
}发布于 2012-09-17 23:05:45
也许是这样的?
def akka(artifact: String) = "com.typesafe.akka" % ("akka-" + artifact) % "2.0.3"
libraryDependencies ++= Seq(akka("actor"), akka("slf4j"), akka("testkit") % "test" )https://stackoverflow.com/questions/12460415
复制相似问题