SBT:如何访问环境变量或配置? [英] SBT: How to access environment variable or configuration?

查看:86
本文介绍了SBT:如何访问环境变量或配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布到内部Nexus存储库。我们有两个仓库,开发和生产。开发人员使用开发仓库,构建团队使用生产仓库,他们可以从安全区域中的机器访问生产仓库。我想添加一个环境变量或SBT配置,以默认值 dev定义STAGE。在生产构建框上,STAGE将被覆盖为生产。我怎样才能做到这一点?我可以在build.sbt文件中定义阶段,并在publishTo任务中使用它,但是我无法弄清楚如何从环境中获取价值。这是我的东西。

  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( nexus的快照 + s +-snapshots-m2)
else
Some( nexus + s的发行 +-releases-m2)
}


解决方案

您可以在系统属性中传递阶段并将其读取为设置:

  stage:= sys.props.getOrElse( stage,默认= dev)

使用 sbt -Dstage = production 在构建环境中通过此操作。 / p>

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")
}

解决方案

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.

这篇关于SBT:如何访问环境变量或配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆