我想知道是否可以从主scala源读取设置键的值。
例如,我的build.sbt
包含:
name := "hello"
version := "0.1"
我想在我的scala源文件(version
)中读取name
和src/main/scala/*.scala
的值。这可能吗?
答案 0 :(得分:4)
你需要sbt-buildinfo(https://github.com/sbt/sbt-buildinfo)插件
buildInfoSettings
sourceGenerators in Compile <+= buildInfo
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)
buildInfoPackage := "hello"
它将生成包含您需要的所有属性的scala文件,您可以从scala源访问它们
package hello
/** This object was generated by sbt-buildinfo. */
case object BuildInfo {
/** The value is "helloworld". */
val name = "helloworld"
/** The value is "0.1-SNAPSHOT". */
val version = "0.1-SNAPSHOT"
/** The value is "2.10.3". */
val scalaVersion = "2.10.3"
.....