Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - How Do I Show Version And Build Date/Time In My Application

Tags:

grails

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.

like image 713
David Letteer Avatar asked Oct 11 '22 08:10

David Letteer


2 Answers

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.

like image 104
Stefan Kendall Avatar answered Oct 12 '22 21:10

Stefan Kendall


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

like image 33
add9 Avatar answered Oct 12 '22 22:10

add9