Grails - 如何在我的应用程序中显示版本并构建日期/时间

Dav*_*eer 5 grails

我想知道是否有办法在Grails应用程序的顶部显示版本和构建日期.

编辑:我应该说我正在寻找应用程序构建的日期/时间.

Ste*_*all 3

在您的主模板中或任何地方。

<p style="float:right">Server version: <%=ApplicationHolder.application.metadata['app.version']%></p>
Run Code Online (Sandbox Code Playgroud)

如果您愿意,您可以使用<g:if env="...">环境限制。

构建日期比较棘手,而且可能没有任何意义。你从来不会在同一天建造两次吗?同一时间?我在构建之前将 svn 修订版粘贴到我的应用程序版本中以识别构建,如下所示:

_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();
    }
}
Run Code Online (Sandbox Code Playgroud)

new Date()请注意,您可以仅附加以获取构建日期,而不是附加 svn 修订版。