微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将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"

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐