VOOZH about

URL: https://www.javacodegeeks.com/2016/03/add-auto-update-version-number-play-framework-2-x-project.html

⇱ How to add auto-update the Version Number of a Play Framework 2.X Project - Java Code Geeks


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
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

πŸ‘ Photo of Brian Porter
Brian Porter
March 9th, 2016Last Updated: March 9th, 2016
0 108 1 minute read
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz