How to get project information from build in Scala project code?

一个人想着一个人 提交于 2019-12-24 22:24:49

问题


I have a Scala/sbt project. The project's version is in the sbt Build.scala file.

I need to have an "about" feature that gives the product version to the user. How do I read from the SBT build file from within the Scala source?

For example, given project/Build.scala:

import sbt._

object ApplicationBuild extends Build {
  val appName         = "foo-product"
  val appVersion      = "1.1.0"
}

What I'd really like is to just be able to do ApplicationBuild.appVersion, but that doesn't seem possible.

How can this be achieved?


回答1:


You can use sbt-buildinfo plugin.

The plugin generates a BuildInfo object, which contains information you need.



来源:https://stackoverflow.com/questions/24088273/how-to-get-project-information-from-build-in-scala-project-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!