SBT config injection for different environments

25 Mar 2017

For example, I want different environments for Flyway's SBT tasks. Here is how we can have different variables for 2 different environments:

lazy val ProdConfig = config("prod") lazy val DevConfig = config("dev") inConfig(ProdConfig)(FlywayPlugin.projectSettings ++ Seq( flywayUrl := "jdbc:mysql://...", flywayUser := "root", flywayPassword := "password" )) inConfig(DevConfig)(FlywayPlugin.projectSettings ++ Seq( flywayUrl := "jdbc:mysql://...", flywayUser := "root", flywayPassword := "password" ))

Then, we can run:

sbt prod:flywayMigrate sbt dev:flywayMigrate

SBT is one of the most difficult things I've ever tried to tackle. I couldn't figure out from reading its docs and code on how to achieve this. Eventually, I had to ask on StackOverflow, and thanks to the answer here:

One of the reasons why I couldn't figure out because inConfig wasn't a member of ProdConfig. Instead, it is a global method.

Well, I have learned a little more about SBT.