How to access SBT settings from Java code in PlayFramework?

I have a PlayFramework application and there is name and version in build.sbt .

If I started the playback console, I can access this information by typing name or version .

How can I get this information from Java code inside the application? I cannot find useful methods in Play.application() , and I could not find this in the documentation.

+4
source share
1 answer

To do this, you can use the SBT BuildInfo plugin :

Add to the project /plugins.sbt:

 addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5") 

And for build.sbt:

 buildInfoSettings sourceGenerators in Compile <+= buildInfo buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion) buildInfoPackage := "hello" 

Now you can access the assembly using static methods:

 package controllers; import play.*; import play.mvc.*; import views.html.*; public class Application extends Controller { public static Result index() { return ok(hello.BuildInfo.name());//the name of the application as output } } 
+4
source

All Articles