SBT: How to access environment variable or configuration?

我只是一个虾纸丫 提交于 2020-01-21 02:47:06

问题


I publish to an internal Nexus repository. We have two repos, "dev" and "production". Developers use the dev repo, the build team uses the production repo which they access from machines in a secure area. I would like to add an environment variable or SBT config that defines STAGE with a default value of "dev". On the production build boxes STAGE would be overriden to "production". How can I do this? I am able to define stage in my build.sbt file and use it in the publishTo task, I just can't figure out how to get the value from the environment. Here is what I have.

val stage = settingKey[String]("stage") 

stage := "dev"

publishTo <<= (version, stage) { (v: String, s: String) =>
  val nexus = "http://my-internal-nexus:8081/nexus/content/repositories/"
  if (v.trim.endsWith("SNAPSHOT"))
    Some("snapshots" at nexus + s + "-snapshots-m2")
  else
    Some("releases"  at nexus + s + "-releases-m2")
}

回答1:


You can pass stage in a system property and read it into a setting:

stage := sys.props.getOrElse("stage", default = "dev")

Use sbt -Dstage=production to pass this in your build environment.



来源:https://stackoverflow.com/questions/26406013/sbt-how-to-access-environment-variable-or-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!