How to Add Environment Profile Config to SBT

后端 未结 1 1016
无人及你
无人及你 2020-12-01 12:51

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 continuo

相关标签:
1条回答
  • 2020-12-01 13:26

    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")))
    }
    
    0 讨论(0)
提交回复
热议问题