SBT - Run Task to set a SettingKey

2019-04-09 17:35发布

问题:

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.

回答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.