score:4

Accepted answer

well, one of these you have to set explicitly, then the other one can be calculated:

librarydependencies += "com.company" % "mylib" % (if (name.value.endswith("1.0")) "1.0" else "2.0")`

then during build you could do something like:

sbt> ;compile;publish // <- e.g. for v 1.0
sbt> set name := "myproject-mylib-2.0"
sbt> ;compile;publish // <- e.g. for v 2.0

if you want it more principled you could define a new key:

val isnew = settingkey[boolean]("are we building a new version of a library")
global / isnew := false

name := if (isnew.value) "myproject-mylib-2.0" else "myproject-mylib-1.0"
librarydependencies += "com.company" % "mylib" % (if (isnew.value) "2.0" else "1.0")`

which you would build like

sbt> ;compile;publish // <- for v 1.0
sbt> set isnew := true
sbt> ;compile;publish // <- for v 2.0

or from command line

sbt compile publish "set isnew := true" compile publish

Related Query

More Query from same tag