Monthly Archives: November 2014

Incrementing Grails application version during WAR packaging

Grails comes with several predefined properties, which can be used in application or build process. One of them is application version. It can be found in application.properties file and the usual way is to change it manually. Of course we can find a plugin – version updater – that makes that via Grails console. But what about situation in which every WAR creation should trigger version update?

Quick fix for that can be seen below (it is based on the script I have found on this blog). It is a simple script which should be places in /scripts folder of our project in a file named _Events.groovy. During WAR creation this script will be read and executed. Of course logic presented is fairly simple and lacks some parameters validation but I will leave it up to the developer.


eventCreateWarStart = { warName, stagingDir ->
	
	Map<String,Integer> mappings = [ 'M' : 0, 'm' : 1, 'p' : 2 ]
	String versionParam = System.getProperty('version.update.position', 'M')
	def lastAppVersionNumberList = metadata.'app.version'.split('\\.')
			   
	
	println "*** Started customised version update of Grails app. Current version: ${metadata.'app.version'}"
				
	lastAppVersionNumberList[ mappings[versionParam] ] =        Integer.valueOf(lastAppVersionNumberList[mappings[versionParam]]) + 1
	
	metadata.'app.version' = lastAppVersionNumberList.join('.')
	metadata.persist() 
	
	println "*** Ended customised version update of Grails app. Current version: ${lastAppVersionNumberList.join('.')}"
}
Advertisements

Happy anniversary Chlebik – 200 blog posts and counting

Yep, WordPress does not lie – this post is number 200. When I think who I was back in 2008 (‘Hello World’ published 11th of August 2008) I see a giant leap I made. Moreover, I have managed to ‘jump into’ Java ecosystem and stay there 😉 Starting writing in English was another big step in my career. It is seventh blog post written in English and it seems I am doing quite well.

To make things better – I have decided to start my own GitHub account, to share the code I am presenting in more blog-independent way. I hope it will improve my readers well-being and also helps to spread good code samples around 😉 I was surprised that chlebik account name was not already taken – here it is.

Grails logging class names

I have recently dived into Grails’ logging features. It is simple mechanism but I stumbled upon a problem with class names. If You want to log behaviour in controllers, domains or services – You have to prefix class name with prefix grails.application. So when I tried to log my services i should have write something like this:

warn   'grails.app.services.com.wordpress.chlebik.MyClass'

Instead of:

warn   'com.wordpress.chlebik.MyClass'

The truth is that documentation shows that in code samples – next time – read the manual stupid 😉