我想拥有要发布新版本时自动更新的版本号,因此我着手了解如何使用Play Framework进行此操作。
我发现我可以将其基于sbt-release插件,但是并不是那么简单。 这是我的策略,因此最后我要做的就是运行“ activator release
”:
1.添加插件
通过project/plugins.sbt
下行添加到您的project/plugins.sbt
文件来添加插件:
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.2")
2.更新您的build.sbt文件:
在文件顶部附近添加此导入:
import ReleaseTransformations._
更改版本为:
version := (version in ThisBuild).value
接下来,可以选择在末尾添加这段代码,并注释掉您不想执行的管道阶段(注意:这显然是默认管道) :
releaseProcess := Seq[ReleaseStep](checkSnapshotDependencies, // : ReleaseStepinquireVersions, // : ReleaseSteprunTest, // : ReleaseStepsetReleaseVersion, // : ReleaseStepcommitReleaseVersion, // : ReleaseStep, performs the initial git checkstagRelease, // : ReleaseStep//publishArtifacts, // : ReleaseStep, checks whether `publishTo` is properly set upsetNextVersion, // : ReleaseStepcommitNextVersion // : ReleaseStep//pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured
)
注意:我已经注释掉了自动发布和git push
3.在控制器中获取版本号并传递给模板
public static Result index() {String title = Application.class.getPackage().getImplementationTitle(); String version = Application.class.getPackage().getImplementationVersion(); return ok(index.render(version));
}
并将其显示在模板中:
@(version: String)...
Version: @version
4.发布前确保一切都已提交
5.执行发布
执行发行版后,新版本将存储在文件files.sbt中 。
activator release
- 您可以在sbt-release插件中查找更多选项和可能性,包括在此处自动增加版本的策略: https : //github.com/sbt/sbt-release
翻译自: https://www.javacodegeeks.com/2016/03/add-auto-update-version-number-play-framework-2-x-project.html