将build.sb与project / Build.scala和聚合混合使用

我有这样的事情(简化)之前,使用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 different build.sbt files,it’s still easy to share settings across all projects from the main build,by using the ThisBuild scope to make a setting apply globally.

从而:

// build.sbt
version in ThisBuild := "0.2"

scalaVersion in ThisBuild := "2.9.2"

哇,如果你有二十几把钥匙,这会很糟糕.

相关文章

共收录Twitter的14款开源软件,第1页Twitter的Emoji表情 Tw...
Java和Scala中关于==的区别Java:==比较两个变量本身的值,即...
本篇内容主要讲解“Scala怎么使用”,感兴趣的朋友不妨来看看...
这篇文章主要介绍“Scala是一种什么语言”,在日常操作中,相...
这篇文章主要介绍“Scala Trait怎么使用”,在日常操作中,相...
这篇文章主要介绍“Scala类型检查与模式匹配怎么使用”,在日...