How to add auto-update the Version Number of a Play Framework 2.X Project
I wanted to have Version numbers that get automatically updated when I want to release a new version, so I set about to find out how to do this with Play Framework.
I discovered that I could base it on the sbt-release plugin, but it was not so straight forward. Here is my strategy, so that in the end all I have to do is run “activator release
“:
1. Add the Plugin
Add the plugin by adding this line to your project/plugins.sbt
file:
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.2")
2. Update your build.sbt file:
Add this import near the top of the file:
import ReleaseTransformations._
Change the line with version to this:
version := (version in ThisBuild).value
Next optionally add this piece of code at the end and comment out the pipeline stages you do not want executed (Note: this is apparently the default pipeline):
releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, // : ReleaseStep inquireVersions, // : ReleaseStep runTest, // : ReleaseStep setReleaseVersion, // : ReleaseStep commitReleaseVersion, // : ReleaseStep, performs the initial git checks tagRelease, // : ReleaseStep //publishArtifacts, // : ReleaseStep, checks whether `publishTo` is properly set up setNextVersion, // : ReleaseStep commitNextVersion // : ReleaseStep //pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured )
Note: I have commented out the automatic publish and git push
3. Get the Version Number in a controller and pass to a template
public static Result index() { String title = Application.class.getPackage().getImplementationTitle(); String version = Application.class.getPackage().getImplementationVersion(); return ok(index.render(version)); }
And display it in the template:
@(version: String) ... Version: @version
4. Make sure everything is committed before you release
5. Execute the release
Once you execute the release, the new version will be stored in a file versions.sbt .
activator release
- You can lookup more options and possibilities for the sbt-release plugin, including strategies for auto incrementing the version here: https://github.com/sbt/sbt-release
Reference: | How to add auto-update the Version Number of a Play Framework 2.X Project from our JCG partner Brian Porter at the Poornerd blog. |