Generate build info source file in Maven project (similar to SBT Buildinfo)

136 Views Asked by At

I used to use https://github.com/sbt/sbt-buildinfo to generate source code files in my Scala project to access information such as the project version from within the code. SBT BuildInfo generates code that looks like the following:

case object BuildInfo {
  val name: String = "helloworld"
  /** The value is "0.1-SNAPSHOT". */
  val version: String = "0.1-SNAPSHOT"
  ...
}

I need to do the same in a Maven project. I tried to use mvn artifact:buildinfo which generates similar information, but the output is a plaintext file non-acceessible from within the code (it also uses non-static naming, making it annoyingly difficult to find programmatically):

helloworld-0.1-SNAPSHOT.buildinfo

name=helloworld
group-id=com.my-group
artifact-id=helloworld
version=0.1-SNAPSHOT

My final goal is to be able to display such information on the application startup splash screen.

Example:

private def printBannerAndBuildInfo(): Unit = {
println(banner)
println(s"""Build information:
             |  Version         : ${BuildInfo.version}
             |  Scala version   : ${BuildInfo.scalaVersion}
             |  JDK version     : ${BuildInfo.jdkVersion}
             |  Git commit hash : ${BuildInfo.gitCommitHash}
             |  Git work dir    : ${if (BuildInfo.gitWorkDirStatus) "clean" else "dirty"}
         """.stripMargin)
 }

Is there anything readily available to achieve so in a Maven project? Thanks

0

There are 0 best solutions below