Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically increment version number from my sbt and uploaded to git

Tags:

git

scala

sbt

How do I can increment project version number from my build.sbt file so that when you compile it automatically uploads to git?

like image 779
NaseemMahasneh Avatar asked May 14 '19 12:05

NaseemMahasneh


2 Answers

The sbt-release plugin will do all of this for you.

If you issue the command sbt release from the command line, this plugin will remove the -SNAPSHOT suffix, tag, commit and push the changes to your repository, build, test and release the artifact, then update the version version number (adding the -SNAPSHOT suffix back again), committing the changes once more.

All of the above steps can be customized if necessary.

like image 155
Mike Allen Avatar answered Sep 29 '22 21:09

Mike Allen


You can use the sbt-release plugin.

Steps

  1. Create a plugins.sbt file at specified location(./project/plugins.sbt) in your project.
  2. Add the latest addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") plugin in plugins.sbt file.
  3. Add the following content in build.sbt file.
import ReleaseTransformations._

releaseVersionBump := sbtrelease.Version.Bump.Next
releaseVersionFile := baseDirectory.value / "version.sbt"

publishConfiguration := publishConfiguration.value.withOverwrite(true)
releaseIgnoreUntrackedFiles := true

releaseProcess := Seq[ReleaseStep](
  checkSnapshotDependencies,              // : ReleaseStep
  inquireVersions,                        // : ReleaseStep
  runClean,                               // : ReleaseStep
  runTest,                                // : ReleaseStep
  setReleaseVersion,                      // : ReleaseStep
  commitReleaseVersion,                   // : ReleaseStep, performs the initial git checks
  tagRelease,                             // : ReleaseStep
  publishArtifacts,                       // : ReleaseStep, checks whether `publishTo` is properly set up
  releaseStepTask(publish in Docker),     // : ReleaseStep, publish the docker image in your specified repository(e.i. Nexus)
  setNextVersion,                         // : ReleaseStep
  commitNextVersion,                      // : ReleaseStep
  pushChanges                             // : ReleaseStep, also checks that an upstream branch is properly configured
)
  1. Create a version.sbt file in the project's root directory.
  2. Add this version in ThisBuild := "1.0.0-SNAPSHOT" in version.sbt file.
  3. Finally you can run/use the following command(sbt release or sbt 'release with-defaults')

Note:

  • I have added releaseStepTask(publish in Docker) in the ReleaseStep to automatically build/push docker images in your specified repository(e.i. Nexus).
  • So to use this releaseStepTask(publish in Docker) step you need to add one sbt-native-packager(addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.6")) in plugins.sbt file.
like image 33
Keshav Lodhi Avatar answered Sep 29 '22 20:09

Keshav Lodhi