Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

sbt

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, e.g.

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

...but none worked.

like image 423
0__ Avatar asked Jul 27 '12 18:07

0__


1 Answers

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.

like image 54
0__ Avatar answered Oct 06 '22 10:10

0__