sbt-buildinfo plugin: How can I add the java version in effect at compile time to the generated BuildInfo.scala?

404 views Asked by At

The build info plugin is working fine for me, but I am wondering if I could add to the generated BuildInfo.scala source file the version of the JDK with which it was generated.

2

There are 2 answers

0
0__ On BEST ANSWER

The following should do

buildInfoKeys += BuildInfoKey.action("javaVersion")(sys.props("java.version"))

The four properties you might want to capture are "java.vm.name", "java.vm.version", "java.version", "java.runtime.version".

2
pme On

You can add a SettingKey, like:

lazy val jdkVersion: SettingKey[String] = SettingKey[String]("jdkVersion", "JDK Version")

lazy val root = (project in file(".")).
  enablePlugins(BuildInfoPlugin)
  .settings(
    ThisBuild / jdkVersion := System.getProperty("java.version"),
    buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion, jdkVersion),
    buildInfoOptions += BuildInfoOption.ToJson,
    buildInfoPackage := "myproject.version"
  )