播放框架:从Build.sbt中读取版本 [英] Play Framework: Reading Version from Build.sbt

查看:110
本文介绍了播放框架:从Build.sbt中读取版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直看到很多有关如何从build.sbt中读取版本的问题,并且提供了许多变通方法来将build.sbt指向conf/application.conf并具有而是在conf/application.conf中指定的版本.

I've been seeing a bunch of questions about how to read a version from build.sbt, and there have been a lot of work-arounds provided for how to point build.sbt to conf/application.conf and have the version specified in conf/application.conf instead.

我有一个Configuration对象,需要获取该版本.我目前有这样的设置(如何获取应用程序播放框架和build.sbt 中的版本),其中来自application.conf的配置对象.但是,我仍然想直接从build.sbt获取它.我怎样才能做到这一点?我是否应该在build.sbt文件上运行bash命令以从那里获取版本?有什么建议吗?

I have a Configuration object that needs to get in the version. I currently have it set up like this (How get application version in play framework and build.sbt), where the Configuration objects from application.conf. However, I'd still like to get it directly from build.sbt. How can I do that? Should I perhaps run a bash command on the build.sbt file to get the version from there? Any suggestions?

谢谢!

推荐答案

我们设法通过build-info获取信息,这是一些详细的配置.

We managed to get information via build-info, here's some detail configuration.

  1. project/plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.4")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.5.0")

  • build.sbt

    enablePlugins(BuildInfoPlugin)
    
    enablePlugins(GitVersioning)
    
    buildInfoKeys := Seq[BuildInfoKey](organization, name, version, BuildInfoKey.action("gitVersion") {       
       git.formattedShaVersion.?.value.getOrElse(Some("Unknown")).getOrElse("Unknown") +"@"+ git.formattedDateVersion.?.value.getOrElse("")        
    })
    
    buildInfoPackage := "version"
    

  • 在视图(* .html.scala)内,只需通过

  • Within views (*.html.scala), display those info simply by

    Version @version.BuildInfo.version - build @version.BuildInfo.gitVersion
    

  • 或者您可以通过调用version.BuildInfo.XX

    这篇关于播放框架:从Build.sbt中读取版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆