David Letteer
David Letteer

Reputation: 83

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

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.

Upvotes: 5

Views: 2178

Answers (3)

Sudhir N
Sudhir N

Reputation: 4096

Any one looking for the solution for grails 3. It can be done by configuring the buildProperties task

buildProperties {
    inputs.property("info.app.build.date", new Date().format('yyyy-MM-dd HH:mm:ss'))
}

 <g:meta name="info.app.build.date"/>

See Adding build date and other custom info to war

Upvotes: 0

add9
add9

Reputation: 1503

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

Upvotes: 1

Stefan Kendall
Stefan Kendall

Reputation: 67822

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.

Upvotes: 3

Related Questions