开发者

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

开发者 https://www.devze.com 2023-03-26 18:13 出处:网络
I\'d like to know if there is a way to display the version and build date at the top of my Grails app开发者_如何学Clication.

I'd like to know if there is a way to display the version and build date at the top of my Grails app开发者_如何学Clication.

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消