9

I've the following build.sbt:

name := "it-config-sbt-project"

scalaVersion := "2.10.4"

Defaults.itSettings

lazy val `it-config-sbt-project` = project.in(file(".")).configs(IntegrationTest)

How could I make the line where I add the IntegrationTest configuration even simpler?

I would rather like to have a setting with current configurations and settings of the project, e.g.

settings ++= Defaults.itSettings

configs += IntegrationTest

or even have the itSettings settings applied automatically with the following line in the sbt file:

configs += IntegrationTest
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
  • I don't think a better way is currently available, but I hope to learn that I am wrong. – Seth Tisue Oct 22 '13 at 01:39
  • 1
    There's a better way, but not much - use `project in file(".") configs(IntegrationTest)`. – Jacek Laskowski Oct 29 '13 at 22:16
  • @JacekLaskowski your shorter version didn't work for me: `found: sbt.Project required: sbt.Def.SettingsDefinition` – Caoilte Dec 14 '13 at 17:47
  • @Caoilte are you using sbt 0.13+? Seems so given the message. Did you use `lazy val `it-config-sbt-project` = project in file(".") configs IntegrationTest`? What's your whole `build.sbt`? – Jacek Laskowski Dec 14 '13 at 20:34
  • 2
    I did use lazy val as in your OP and that works fine. I thought you were suggesting in your later comment that the lazy val wasn't needed, whereas actually I think you were pointing out that the brackets were optional. – Caoilte Dec 15 '13 at 11:44
  • This is by the far the simplest I've ever seen, I can't remember how I first stumbled upon this but wish it was referenced in more places. – samthebest Jun 15 '16 at 04:19

3 Answers3

5

I found myself similarly frustrated. The best solution I have found is to borrow from Josh Suereth's Effective SBT slides and create a project helper function that adds the IntegrationTest configuration for you.

eg

object BasePlugin extends Plugin {
  val baseSettings = Defaults.itSettings

  def baseProject(name: String, location: String = "."): Project = (
    Project(name, file(location)) configs(IntegrationTest)
  )
}

I pull this and a bunch of other settings in as a plugin and then my build.sbt is as simple as

import caoilte.BasePlugin

BasePlugin.baseSettings

val helloWorld = BasePlugin.baseProject("helloWorld")
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Caoilte
  • 2,381
  • 1
  • 21
  • 27
2

sbt needs to know the configurations for delegation before evaluating settings. So, configurations can't be defined inside the settings system.

Note that if using a configuration that doesn't extend another configuration, it isn't strictly necessary to register it on the Project with the configs method though.

Mark Harrah
  • 6,999
  • 1
  • 26
  • 31
1

I am assuming that you are using SBT 0.13 as you have your project definition inside .sbt file.

There is a new feature called autoSetting that you can use to influence the combined .sbt settings from multiple sbt files.

http://www.scala-sbt.org/0.13.0/docs/Community/ChangeSummary_0.13.0.html#control-over-automatically-added-settings

An example will be:

lazy val `it-config-sbt-project` = project.in(file("."))
  .autoSettings(userSettings, allPlugins, sbtFiles(file("../mysetting.sbt")), defaultSbtFiles)
suriyanto
  • 1,075
  • 12
  • 19