generating build info
Dec. 30th, 2015 01:53 pmval buildInfoGenerator = taskKey[Seq[File]]("versionInfo") def buildInfo: String = { def stringLiteral(s: String) = "\"" + s.trim.replaceAll("\\n", "; ") + "\"" val gitInfo = stringLiteral(("git show --summary" !!) split "\\n" take 4 mkString "; ") s""" /* Build Information */ object BuildInfo { // (does not compile) val BuildDate = new org.joda.time.DateTime(${System.currentTimeMillis()}L) val BuildDate = new java.util.Date(${System.currentTimeMillis()}L) val BuildNumber = ${sys.env.get("BUILD_NUMBER") map stringLiteral} val BuildId = ${sys.env.get("BUILD_ID") map stringLiteral} val Hostname = ${stringLiteral("hostname" !!)} val GitInfo = $gitInfo val GitBranch = ${stringLiteral("git rev-parse --abbrev-ref HEAD" !!)} } """ } def generate(folder:File): Seq[File] = { println(s"Generating in $folder") val file = folder / "BuildInfo.scala" val contents = buildInfo IO.write(file, contents) Seq(file) } buildInfoGenerator in Compile := generate((sourceManaged in Compile).value) sourceGenerators in Compile <+= (buildInfoGenerator in Compile).toTask
The thing is, I could not yet figure out how to include this into project(s).