I am not sure you can fix this without changing your TaskKey to a SettingKey.
However there is already a plugin which gives you most of what you need: sbt-git
I tried the following: In project/plugins.sbt
:
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.2")
Then build.sbt
looks like this:
name := "Foo"
git.baseVersion := "1.0"
version := {
val branch = git.gitCurrentBranch.value
val isDev = branch != "master"
val v = git.baseVersion.value
val date = new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date)
if (isDev) v + "-" + date
else v
}
Running sbt version
in master gives the short version, running in other branch gives dated version.