Ankur Tripathi

Grails

Using PostConstruct annotation with Grails Services

We can use PostConstruct with Grails Services and injected Spring Beans. This PostConstruct annotation can be used to annotate a method which needs to be executed after dependency injection to perform any initialization. [code] import javax.annotation.PostConstruct class PostConstructDemoService { @PostConstruct private...

27-Aug-2012

Grails

Setting JVM args for grails run-war

While working on my project using Grails 2.0.3, I was getting java.lang.OutOfMemoryError with grails run-war even when my JAVA_OPTS are set. Then while going through documentation and this thread i found how to set jvm args for grails run-war. Just add this code in your BuildConfig.groovy and you are done. [code]...

19-May-2012

Grails

Extending Audit Logging Plugin to track changes to Persistent Collections

In one of our project we needed to maintain history of domain objects when they are updated. We saw Grails Audit Logging Plugin as a good candidate. But later, found that it doesn't take care of persistent collections. So with help of my colleague Vivek and this Stack Overflow thread, we extended this plugin without making it inline, to...

23-Jan-2012

Grails

Specifying default package for all Grails artefacts

Hi All, Today i found how to specify default package for all Grails artefacts, would like to share with you. By default when we create any domain, controller or any other artefact, It takes application name as default package. If you want to change that just define grails.project.groupId property in your Config.groovy. [code]...

20-Jul-2011

Grails

New way To Configure a RuleSet for Static Groovy Code analysis using CodeNarc plugin

The CodeNarc plugin provides static code analysis using CodeNarc library. CodeNarc analyzes Groovy code for defects, bad practices, inconsistencies, style issues etc. CodeNarc provides a Groovy DSL for defining RuleSets. Install CodeNarc plugin into you grails project. Now create one groovy file say CustomRules.groovy and add following...

08-Mar-2011

Grails

Multiple Variable Assignment in Groovy

In one of my project, I was in need to return multiple variables from a method. I searched and found very good Groovy way for 'Multiple Assignment', This allows us to assign multiple variables at once. [groovy]def (str1,str2,str3) = ['Groovy','and','Grails'] assert str1 == 'Groovy' && str2 == 'and' &&...

14-Dec-2010

Grails

Creating custom codec in Grails

Grails applications can define their own codecs and Grails will load them along with the standard codecs. A custom codec class must be defined in the grails-app/utils/ directory and the class name must end with 'Codec'. For more information see Dynamic Encoding Methods. [java] import java.security.MessageDigest import...

13-Nov-2010