Home > OS >  How to specify project version that only sbt publishLocal should use?
How to specify project version that only sbt publishLocal should use?

Time:01-14

I am switching my open source projects from sbt-release to sbt-ci-release in order to automate my releases.

Currently with sbt-release, it manages a version.sbt file which contains:

ThisBuild / version := <lastReleasedVersion>-SNAPSHOT

sbt-release updates this file as part of the release process, so any time I used sbt publishLocal, the project gets published locally with the same consistent version number (e.g. 0.1.3-SNAPSHOT) until I release the project to Maven (e.g. as 0.1.3), and then sbt-release updates the version in version.sbt to 0.1.4-SNAPSHOT.

In contrast, sbt-ci-release is designed differently, and its docs tell me to remove any version := ... statements from my build.sbt, because it manages the version itself. Because of this, I had to delete the version.sbt file, and so now when I publishLocal the project locally, it gets published with a unique version number like 0.1.2 4-a5b1da75 20230103-2217-SNAPSHOT. This version number includes the last git commit hash and a timestamp of the latest local change.

I don't want such a snapshot versioning scheme – it requires me to update the build.sbt file of the other local project that depends on this one every time I publishLocal a change. With the previous behaviour I only needed to sbt reload the consuming project to get the changes, now I need to also copy paste version numbers. I understand that more specific snapshot version numbers can be safer, but with local development I am optimizing for speed, not safety.

So my question is – how can release locally with a consistent SNAPSHOT version number that doesn't change on every commit, without manual busywork like typing version := "whatever" into sbt console? I want to keep using sbt-ci-release for production releases in CI (Github Actions) too.

Is there a way to use a custom version number with the publishLocal command specifically? There must be a way to build the custom sbt command / task that I need, but I just don't know how.

CodePudding user response:

sbt-ci-release uses sbt-dynver for the versioning.

You should be able to customize the version format according to their documentation at the cost of a bit of code in your projects.

  • Related