简体   繁体   中英

Mixing build.sbt with project/Build.scala and aggregates

Before I had something like this (simplified), using 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
   )
}

But I want to keep as much information as possible in the plain build.sbt file. So now I have

// build.sbt
version      := "0.2"

scalaVersion := "2.9.2"

And

// project/Build.scala
import sbt._
import Keys._

object MyBuild extends Build {
   lazy val main = Project(
      id        = "main",
      base      = file( "." ),
      aggregate = Seq( sub )
   )

   lazy val sub = Project(
      id        = "main-sub",
      base      = file( "sub" )
   )
}

But that doesn't seem to mix in my settings from build.sbt into the sub projects:

> 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

How to remedy this? I also tried to add explicit settings to the sub-project, eg

  • settings = Defaults.defaultSettings
  • settings = Project.defaultSettings
  • settings = MyBuild.settings
  • settings = main.settings (sure this one should do?!)

...but none worked.

The information is a bit hidden in the last section of 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.

Thus:

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

scalaVersion in ThisBuild := "2.9.2"

Wow, that sucks big time if you have two dozen keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM