I'd like to know if there is a way to display the version and build date at the top of my Grails application.
Edit: I should have said I'm looking for the Date/Time the app was built.
In your main template, or wherever.
<p style="float:right">Server version: <%=ApplicationHolder.application.metadata['app.version']%></p>
You can use <g:if env="...">
to limit by environments if you wish.
Build date is trickier, and probably doesn't mean anything. Do you never build twice on the same day? Same hour? I'm sticking the svn revision in my application version before the build to identify builds, as such:
_Events.groovy
eventWarStart = { type ->
addSvnRevisionToAppVersion()
}
private def addSvnRevisionToAppVersion() {
try {
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
SVNClientManager clientManager = SVNClientManager.newInstance();
SVNWCClient wcClient = clientManager.getWCClient();
File baseFile = new File(basedir);
SVNInfo svninfo = wcClient.doInfo(baseFile, SVNRevision.WORKING);
def svnRevision = svninfo.getRevision().number;
String oldVersion = metadata.'app.version'
String newVersion
if (oldVersion.matches(/.*\.r\d+/)) {
newVersion = oldVersion.replaceAll(/\.r\d+/, ".r${svnRevision}");
}
else {
newVersion = oldVersion + ".r${svnRevision}".toString()
}
metadata.'app.version' = newVersion
metadata.persist()
}
catch (SVNException ex) {
println "**************** SVN exception **************"
println ex.getMessage();
}
}
Note that instead of appending svn revision, you could just append new Date()
to get the build date.
i havent tried it my self but there is something like
grails set-version 20110101-3
def version = grailsApplication.metadata['app.version']
for more info refer to documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With