简体   繁体   中英

How to export version from build.sbt to application.conf in Play?

In build.sbt there's the setting:

version := "0.1.0"

How can I propagate its value to application.conf in Play:

app.ver = // the value of version from build.sbt

Please advise.

Do you need the value to be explicitly set in application.conf or just to be available at runtime? For this purpose I'm using the SBT Buildinfo plugin

Why don't you do it the other way around?

In application.conf :

application.version="0.1.0"

In build.sbt :

import com.typesafe.config._

val confPath = Option(System.getProperty("config.file")).getOrElse("conf/application.conf")
val conf = ConfigFactory.parseFile(new File(confPath)).resolve()

version := conf.getString("application.version")

Another advantage to do it this way is that you have very easy access to the application version from within your application, eg, for showing it in the footer of a page, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM