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

故事扮演 提交于 2021-02-16 16:41:25

问题


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


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/56130795/how-to-automatically-increment-version-number-from-my-sbt-and-uploaded-to-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!