4

So my general problem is that I want to set the version key based on the result of a task. However the version key is set before the task is run. From what I understand I can't change the value of a key once it is set so I can't change this within my task.

What I want to do is run the task as a dependency to the publish task and change the value for version. I feel like there must be a way to do this, but I have no clues at the moment. Any help would be greatly appreciated.

  • possible duplicate of [How to change setting inside SBT command?](http://stackoverflow.com/questions/14262798/how-to-change-setting-inside-sbt-command) – Jacek Laskowski Oct 17 '14 at 21:38

1 Answers1

1

The sbt-release plugin does this by writing an sbt file in the root of the project containing the correct version. Maybe you can use this plugin: https://github.com/sbt/sbt-release

If you can not use it you can check out the source code to see the strategy the creator used.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • Yeah, I ended up going this route but left the question open to see if anyone else had a different approach. It seems they reapply all the settings (I assume the way `set key := value` works in SBT console) but it seems kinda hacky. Maybe that's just the best way to work with SBT... who knows. –  Oct 22 '14 at 12:54
  • @John `set key := value` copies the settings (with the new key value pair) and reloads the project. – EECOLOR Oct 25 '14 at 09:02
  • What is the api to do that within `Build.scala` rather than the `.sbt` file format? I like to keep things a little more explicit and a less magical in my build definitions. –  Oct 27 '14 at 10:24
  • I have no idea, the `set` commands seems to be a built-in command (I am not even sure it is a normal sbt command). – EECOLOR Oct 27 '14 at 16:53
  • Did some looking around, seems that `set` is a wrapper to `BuiltinCommands.reapply` (see http://www.scala-sbt.org/0.13.6/api/index.html#sbt.BuiltinCommands$) –  Oct 28 '14 at 17:30
  • Extracted definition of `set`: https://gist.github.com/JohnMurray/b3e89764a48fef96a356 –  Oct 28 '14 at 17:34