6

I'm trying to create/configure environment-specifc distributions (for development, quality and production) using the sbt native packager functionality available in Play (2.2). I tried to achieve this using the following settings in a build.sbt file:

val dev  = config("dev")  extend(Universal)
val qual = config("qual") extend(Universal)
val prod = config("prod") extend(Universal)


def distSettings: Seq[Setting[_]] =
  inConfig(dev)(Seq(
    mappings in Universal <+= (resourceDirectory in Compile) map { dir =>
     println("dev")
     (dir / "start.bat.dev") -> "bin/start.bat"
     // additional mappings
   }
  )) ++
  inConfig(qual)(Seq(
    mappings in Universal <+= (resourceDirectory in Compile) map { dir =>
      println("qual")
      (dir / "start.bat.qual") -> "bin/start.bat"
      // additional mappings
    }
  )) ++
  inConfig(prod)(Seq(
    mappings in Universal <+= (resourceDirectory in Compile) map { dir =>
      println("prod")
      (dir / "start.bat.prod") -> "bin/start.bat"
      // additional mappings
    }
  ))


play.Project.playScalaSettings ++ distSettings

In the SBT console, when I'm typing "dev:dist" I was expecting to see only "dev" as output and correspondingly only the corresponding mappings to be used. Instead, it looks like all mappings across all configs are merged. Most likely I don't understand how configs are supposed to work in SBT. In addition, there might be better approaches which achieve what I'm looking for.

Martin Studer
  • 2,213
  • 1
  • 18
  • 23
  • Note: This question was already posted at https://groups.google.com/forum/#!topic/play-framework/gdTv_hPxBq0 but I decided that SO might be a better fit in this case. – Martin Studer Dec 12 '13 at 07:50

1 Answers1

2

inConfig(c)( settings ) means to use c as the configuration when it isn't explicitly specified in settings. In the example, the configuration for mappings is specified to be Universal, so the mappings are all added to the Universal configuration and not the more specific one.

Instead, do:

inConfig(prod)(Seq(
  mappings <+= ...
))

That is, remove the in Universal part.

Note: because the more specific configurations like prod extend Universal they include the mappings from Universal.

Mark Harrah
  • 6,999
  • 1
  • 26
  • 31
  • 1
    Ok, I see. If I do this, however, I now get an error saying "References to undefined settings: /prod:mappings from /prod:mappings" (same for dev:mappings and qual:mappings). – Martin Studer Dec 19 '13 at 08:17