Grails console plugin gotcha

28 / Aug / 2011 by Uday Pratap Singh 0 comments

Grails console plugin is one of those which I always add to my projects. It really gives you a very handy way of debugging things and also run some quick fixes.

Whenever you hit the console action you always gets a predefined message on it about the available variables, which is really good when you are a new user but in most of the cases you need to import few statements and you always need to write them before executing any command.

So in my recent project I looked at the plugin code and I found a nice way to change the default statements.

I added the following line in my project application filter.

consoleImports(controller: 'console', action: '*') {
     before = {
             String importStatements = """import com.intelligrape.package1.*
             import com.intelligrape.package2.*
             import com.intelligrape.package3.*
             import com.intelligrape.package4.* """
 
             session['_grails_console_last_code_'] = session['_grails_console_last_code_'] ?:importStatements 
      }
}



It could be a small but great enhancement in the console plugin to just update it to provide the starting code as a configuration option

Hope it helps
Uday Pratap Singh
uday@intelligrape.com

FOUND THIS USEFUL? SHARE IT

Leave a comment -