Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment-specific distributions using sbt native packager

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.

like image 805
Martin Studer Avatar asked Dec 12 '13 07:12

Martin Studer


1 Answers

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.

like image 168
Mark Harrah Avatar answered Oct 17 '22 08:10

Mark Harrah