Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add Environment Profile Config to SBT

Tags:

sbt

In Maven you can have Profiles, which can set up a build configuration for different environments. For example DEV, QA, UAT, PRODUCTION

In order to support continuous integration, there must be a way to tell SBT which environment to run against.

how to set up for different environments in SBT. For example DEV, QA, UAT, PRODUCTION?

thanks

like image 430
evan Avatar asked Jun 19 '13 14:06

evan


People also ask

How do I set environment variables in sbt?

Then to easily add the environment variable, open the windows menu then type environment, and pick the first option: That takes you directly to the advanced system properties dialog: Then just pick Environment Variables, and paste the copied path in to your PATH.

What is sbt Dist?

sbt-package-dist is a plugin for sbt 0.11 which attempts to codify best practices for building, packaging, and publishing libraries and servers. It adds the following features: a "package-dist" task for creating a deployable distribution of a server, including an executable jar and a build.

What does sbt stage do?

The stage command is part of sbt-native-packager that: The goal [of the plugin] is to be able to bundle up Scala software built with SBT for native packaging systems, like deb, rpm, homebrew, msi. > help stage Create a local directory with all the files laid out as they would be in the final distribution.


1 Answers

You can do this by creating a custom configuration.

val ProfileDev = config("dev") extend(Runtime)
val ProfileQA  = config("qa") extend(Runtime)

val root = (project in file(".")).
  configs(ProfileDev, ProfileQA). // add config here!
  settings( 
    name := "helloworld",
    ....
  ).
  settings(inConfig(ProfileDev)(Classpaths.configSettings ++ Defaults.configTasks ++ Defaults.resourceConfigPaths ++ Seq(
    unmanagedResourceDirectories += {baseDirectory.value / "src" / configuration.value.name / "resources"}
  )): _*).
  settings(inConfig(ProfileQA)(Classpaths.configSettings ++ Defaults.configTasks ++ Defaults.resourceConfigPaths ++ Seq(
    unmanagedResourceDirectories += {baseDirectory.value / "src" / configuration.value.name / "resources"}
  )): _*)

You then place your config file in src/dev/resources and src/qa/resources, and it should be part of your classpath when you say dev:run or dev:package. Here's a quick test:

object Main extends App {
  println(xml.XML.load(this.getClass.getResource("/config.xml")))
}
like image 69
Eugene Yokota Avatar answered Sep 28 '22 03:09

Eugene Yokota