Send module version as command line argument to SBT

送分小仙女□ 提交于 2019-12-19 04:20:50

问题


I am using TeamCity to run a bash script that is utilizing SBT Native Packager to publish an image to Docker. The sbt portion of the bash script looks something like this:

sbt -DdockerRepository=$repo -DpackageName=$packageName -D myproject/docker:publish

I want to pass on the TeamCity build number as a version number to my package. Today I specify the version number manually in settings in build.sbt:

settings(
  version := "0.20",
  ....,
  dockerBaseImage := "example.com:5000/linux/java8:latest",
  dockerRepository in Docker := Some("example.com/myoldrepo"),
  dockerUpdateLatest := true'
)

I want to be able to do it like this:

activator -Dversion=0.21 -DpackageName=myproject -D myproject/docker:publish

but this does not seem to work. Yet overriding the dockerRepository like I do above is working.

How can I pass my desired version number into SBT from the command line/TeamCity?


回答1:


You could set version before publish:

sbt 'set version := "1.0"' docker:publish



回答2:


Try something like this:

val myVersion = util.Properties.propOrNone("version").getOrElse("0.20")

val myDockerBaseImage = util.Properties.propOrNone("dockerBaseImage").
                    getOrElse("example.com:5000/linux/java8:latest")

lazy val myProject = Project("myProject",file("path")).settings(
  version := myVersion,
  dockerBaseImage := myDockerBaseImage,
  ....,
  dockerRepository in Docker := Some("example.com/myoldrepo"),
  dockerUpdateLatest := true
)

And then call it (depends on your sbt installation):

SBT_OPTS="-Dversion=0.21" sbt

sbt -Dversion=0.21

activator -Dversion=0.21



来源:https://stackoverflow.com/questions/36327795/send-module-version-as-command-line-argument-to-sbt

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