在我有这样的事情(简化)之前,使用sbt 0.11.3:
// project/Build.scala import sbt._ import Keys._ object MyBuild extends Build { lazy val standardSettings = Defaults.defaultSettings ++ Seq( version := "0.2",scalaVersion := "2.9.2" ) lazy val main = Project( id = "main",base = file( "." ),settings = standardSettings,aggregate = Seq( sub ) ) lazy val sub = Project( id = "main-sub",base = file( "sub" ),settings = standardSettings ) }
但是我希望在plain build.sbt文件中保留尽可能多的信息.所以现在我有
// build.sbt version := "0.2" scalaVersion := "2.9.2"
和
// project/Build.scala import sbt._ import Keys._ object MyBuild extends Build { lazy val main = Project( id = "main",base = file( "sub" ) ) }
但是在我的设置中,似乎没有将build.sbt混合到子项目中:
> show version [info] main-sub/*:version [info] 0.1-SNAPSHOT [info] main/*:version [info] 0.2 > show scala-version [info] main-sub/*:scala-version [info] 2.9.1 [info] main/*:scala-version [info] 2.9.2
> settings = Defaults.defaultSettings
> settings = Project.defaultSettings
> settings = MyBuild.settings
> settings = main.settings(确定这个应该做什么?!)
……但都没有用.
解决方法
这些信息在
sbt’s Multi Projects documentation的最后一部分中有点隐藏:
When having a single
.scala
file setting up the different projects,it’s easy to use reuse settings across different projects. But even when using differentbuild.sbt
files,it’s still easy to share settings across all projects from the main build,by using theThisBuild
scope to make a setting apply globally.
从而:
// build.sbt version in ThisBuild := "0.2" scalaVersion in ThisBuild := "2.9.2"
哇,如果你有二十几把钥匙,这会很糟糕.