Rich Oliver February 2016

sbt how to define scoped setting in scala code

Although I'm using a multi project build for some projects, I don't want to put all my projects in one build. Yet I want to be able to define certain settings in one place for multiple builds. So the best way seems to be, to create a Scala file and then link to it from each project sub directory. So creating the following code in the project sub directory:

import sbt._
import Keys._
import AddSettings._

object RBuild extends Build
{     
  override lazy val settings: Seq[Def.Setting[_]] = super.settings ++ Seq(
  scalaVersion := "2.11.7",
  scalaSource in Compile := baseDirectory.value / "src",
  scalaSource in Test := baseDirectory.value / "testSrc",       
  unmanagedSourceDirectories in Compile := Seq(baseDirectory.value / "src"),
  unmanagedSourceDirectories in Test := Seq(baseDirectory.value / "src"),
  scalacOptions ++= Seq("-feature", "-language:implicitConversions", "-deprecation", "-target:jvm-1.8"))
}

The scalaVersion works, but none of the settings to the source directories have any effect on the build, whether set individually or in combination. They are still the same as their defaults. What am I doing wrong? I'm not sure if the scalacOptions setting is effective or not from using the inspect command in the sbt terminal.

Answers


Rich Oliver February 2016

I came across this searching for a solution to a different problem. Set the settings in the project:

import sbt._
import Keys._
import AddSettings._

object RBuild extends Build
{
  lazy val root = (project in file(".")).settings(
  scalaVersion := "2.11.7",
  scalaSource := (baseDirectory.value / "src"),
  scalaSource in Test := baseDirectory.value / "testSrc",       
  unmanagedSourceDirectories in Compile := Seq(baseDirectory.value / "src"),
  unmanagedSourceDirectories in Test := Seq(baseDirectory.value / "src"),
  scalacOptions ++= Seq("-feature", "-language:implicitConversions", "-deprecation", "-target:jvm-1.8"))       
}

Although this still doesn't answer the question of why the scalaVersion worked but not the other settings. I presume scalaVersion must be considered a general setting while the others are project specific.

Post Status

Asked in February 2016
Viewed 2,787 times
Voted 12
Answered 1 times

Search




Leave an answer