sbt task to increment project version
Asked Answered
H

2

11

Is there an SBT task to increment a project's version?

Given an initial configuration of something like the following build.sbt

name := 'My Project'

organization := 'org.example'

version := '0.1.0'

and a versioning nomenclature of major.minor.patch, I was hoping for an SBT task like

> incrementVersionPatch

that would result in a version of 0.1.1.

(Ideally also the corresponding incrementVersionMinor and incrementVersionMajor.)

I feel like this must already exist but cannot find a way to do it.

Hilleary answered 15/5, 2014 at 14:48 Comment(0)
S
9

I think what you need is sbt-release plugin that "provides a customizable release process that you can add to your project." with "the setting release-version-file, which is set to file("version.sbt") by default and points to $PROJECT_ROOT/version.sbt".

Showthrough answered 15/5, 2014 at 18:1 Comment(2)
Can you point me to an example? release-version-file doesn't seem to be working in sbt 0.13.15 & sbt-release 1.0.5Barogram
sbt-release does a bunch of things, only one of them is what is asked for here. So if you already have a release process and just want to bump the version, it's not super helpful unfortunately.Vascular
O
0

As @jacek-laskowski answered, the sbt-release plugin can do what you need. It can do a lot more, and in fact it is configured to do the entire release process by default. However, you can use SBT to override the release process so that it only increments the version numbers:

# Minor bump
sbt '
  ; set releaseProcess := Seq(ReleaseTransformations.inquireVersions, ReleaseTransformations.setNextVersion)
  ; set releaseVersionBump := sbtrelease.Version.Bump.Minor
  ; release with-defaults
'

# Major bump
sbt '
  ; set releaseProcess := Seq(ReleaseTransformations.inquireVersions, ReleaseTransformations.setNextVersion)
  ; set releaseVersionBump := sbtrelease.Version.Bump.Major
  ; release with-defaults
'

Note, in order for sbt-release to work, the version must be set in a single file version.sbt with ThisBuild / version := "0.1.0" (or any other version number).

Obsidian answered 2/5 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.