nimavat.me

Java, Groovy, Grails, Spring, Vue, Ionic + Fun blog

Grails 3 - Adding build date and other custom info to war

|

It is very common requirement to add build date, build number, git commit etc. information to war. Lets see an example for how to add build date to war and display it on UI.

Gails gradle plugin adds buildProperties task to gradle build. This task is responsible for creating META-INF/grails.build.info properties file which is included in the war. by default the file contains property values for grails env the war was built with, application name and version as defined in build file, and grails version. 

Properties from grails.build.info file can be accessed using <g:meta> tag

Example.

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

Below is an example of how to add the new property build date to the build info file.

File: build.gradle

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

File: application.yml

    info:
        app:
            name: '@[email protected]'
            version: '@[email protected]'
            grailsVersion: '@[email protected]'
            build:
              date: '@[email protected]'

After that the build date can be displayed on UI using the g:meta tag as shown below.

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

Note: This will only work when deployed as a war because of the fix made for the issue 10641