Thursday, January 12, 2017

Grails automated build number

Grails version 2.4.4

In Grails projects you can write some scripts that will automatically assign a build number.
For example, if you want to set the current date as the build number, you can add a file called _Events.groovy to your scripts folder:

 import java.text.SimpleDateFormat  
 eventCompileStart = { arg ->  
      Date date = new Date()  
      SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd")  
      String buildNumber = dateFormatter.format(date)  
      metadata.'app.buildNumber' = buildNumber  
      println "**** Compiling with build number: ${buildNumber}"  

And if you want to display the build number on screen, then in your GSP file you can use the following:

  ${grailsApplication.metadata['app.buildNumber'] }  

You will notice that in your file the app.buildNumber is automatically populated.

No comments:

Post a Comment