If you do not run your code from the git repository, you can do it like me, I have a script assembly that creates a war file, and in this script I will do:
cat > {apppath}/conf/application_version.properties << EOF application.version=`git describe` application.buildtime=`date` EOF ...
And in the @OnApplicationStart class add properties
private def readApplicationVersion() { Logger.info("Bootstrap.readApplicationVersion file") Play.id match { case "" | "test" => Play.configuration.put("application.version", "TEST-MODE"); Play.configuration.put("application.buildtime", "YEAH BABY YEAH REALTIME") case _ => addFileProp(VirtualFile.open(Play.applicationPath).child("conf/application_version.properties").inputstream()) } } private def addFileProp(input: InputStream) { input match { case null => Logger.error("can't find config file, Play id: " + Play.id + ". Will exit now.") case _ => val extendCconfiguration = IO.readUtf8Properties(input); for (key <- extendCconfiguration.keys) { Play.configuration.put(key, extendCconfiguration.get(key)) } } }
And from the controller
object ApplicationVersion extends Controller { def version = { Json("{iamVersion: '"+configuration.getProperty("application.version")+"', buildTime: '"+configuration.getProperty("application.buildtime")+"'}") } }
source share