问题
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
- Create a
plugins.sbtfile at specified location(./project/plugins.sbt) in your project. - Add the latest
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")plugin inplugins.sbtfile. - Add the following content in
build.sbtfile.
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
)
- Create a
version.sbtfile in the project's root directory. - Add this
version in ThisBuild := "1.0.0-SNAPSHOT"inversion.sbtfile. - Finally you can run/use the following command(
sbt releaseorsbt 'release with-defaults')
Note:
- I have added
releaseStepTask(publish in Docker)in theReleaseStepto 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")) inplugins.sbtfile.
来源:https://stackoverflow.com/questions/56130795/how-to-automatically-increment-version-number-from-my-sbt-and-uploaded-to-git