我有一个项目设置为SBT多构建。看起来像这样:
- project
Dependencies.scala
- core
build.sbt
- server
build.sbt
build.sbt
我想使用Dependencies.scala
作为子项目之间共享的库版本号的容器。
sealed trait Dependencies {
val commonsIo = "2.4"
}
object DependencyVersions extends Dependencies
在root build.sbt中,我添加了一个Setting
给每个子项目。
lazy val dependencies = settingKey[Dependencies]("versions")
val defaultSettings = Defaults.coreDefaultSettings ++ Seq(
dependencies := DependencyVersions)
def projectFolder(name: String, theSettings: Seq[Def.Setting[_]] = Nil) = Project(name, file(name), settings = theSettings)
lazy val core = projectFolder("core", defaultSettings)
我无法访问dependencies
中的core/build.sbt
设置。
"commons-io" % "commons-io" % dependencies.value.commonsIo, <-- doesn't work
我怎样才能让它发挥作用?
答案 0 :(得分:2)
您可以在object Common extends AutoPlugin
(project/Common.scala
)中定义公共设置(依赖项),然后在子项目描述符上使用.enablePlugin(Common)
(请参阅Anorm)
答案 1 :(得分:0)
感谢@cchantep现在正在使用下面的AutoPlugin
import sbt._
sealed trait Dependencies {
val commonsIo = "2.4"
}
object DependencyVersions extends Dependencies
object DependencyVersionsPlugin extends AutoPlugin {
override def trigger = allRequirements
object autoImport {
lazy val dependencies = settingKey[Dependencies]("Bundles dependency versions")
}
import autoImport._
override def projectSettings = Seq(
dependencies := DependencyVersions
)
}