Getting Groovy (and Grails)

Explorations in Groovy and Grails Development

Archive for the ‘Grails’ Category

Review of Conference Published in GroovyMag

leave a comment »

Want to know what you missed (or remember what you experienced) last month at the Gr8 conference in Denmark, Copenhagen? Check out the latest edition of GroovyMag which has a review – including interviews with the organizers.

Written by peterbell

June 4, 2010 at 3:33 pm

Simpler domain name –

leave a comment »

OK, now that I seem to be using this blog for real and on a regular basis, it’s time to simplify the domain name. Instead of (which still works), you can now just get to the blog by going to

In the next couple of months expect a series of postings regarding Domain Specific Languages in Groovy. They’ll be designed to flesh out the three article series I’ll be writing for GroovyMag. Also expect various postings on Groovy and Grails development, from simple tips and techniques to some funky ANTLR preprocessing stuff and some explorations of AST transformations in Groovy 1.7. I’ll probably also include ancillary technologies like some advanced thoughts on using git and my experiences working with Hudson for CI with Grails projects.

Oh, and there will also be some stuff on Gaelyk – really looking forward to playing with that.

So keep an eye on – or just watch for the aggregated posts at the awesome – that’s where I follow all of my favorite Groovy/Grails blogs.

Written by peterbell

May 12, 2010 at 4:46 pm

Posted in Grails, Groovy

Do you know Everything About Groovy and Grails? Gr8 Copenhagen Coming up Soon

leave a comment »

It’s tough. Keeping up with a framework (Grails) on top of a fairly new, quickly evolving language (Groovy) which in turn is built using evolving frameworks (Hibernate, Spring, SiteMesh and via plugins Quartz, Lucene and many others) in a language – Java – which continues to develop (if only at a glacial pace). I notice on the mailing lists that even the top luminaries in the field are occasionally flummoxed by a question. It’s just not possible to know absolutely everything about Groovy and Grails. The good news is that while an individual may not know everything, as a community we know a lot more. The mailing lists are a good resource, but as the community grows you don’t always get an answer to your questions on the lists. What to do?

The answer for me is to do what I’ve done in every other domain I’ve been involved with – get involved with the community. (I’m relatively new to Groovy and Grails, but I’m pretty involved in the Domain Specific Modeling and ColdFusion communities). Helping out on the mailing lists and contributing to plugins is a great way to get started, but it’s hard to beat the face to face interactions you get at user groups and (especially) at conferences. That’s why I decided to go to gr8 in the US, am presenting on DSLs in Sydney, New York and (hopefully) London this month, and will be attending gr8 in Copenhagen next month (even though I can only manage a day as I’m presenting at the BCS SPA conference on DSL design on the Wednesday).

I was lucky enough to attend Gr8 last year. It was an amazing chance to get to know many of the key developers in the community, to build up a set of resources so that if we do ever get stuck on a technical challenge we can get on IM and often get an answer or idea from someone in minutes instead of hours or days of futzing around. Why do I mention this? Well, Gr8 conference is the only dedicated Groovy and Grails conference in Europe and a great opportunity to learn about a whole range of projects within the Groovy ecosystem – including Grails, Griffon, Spock, Gradle and Gaelyk. More than that, it’s a chance to meet up with other developers dealing with the same adoption, implementation and technical challenges that you work with every time you develop a Groovy based project.

There is still time to register for the conference, so think about how much it costs when you’re stuck on a project for a day trying to figure things out, and I hope you can get a cheap flight, a modest hotel and a ticket to the conference into the budget. It’s not cheap, especially with the market right now, but the only thing more expensive than going to the conference? Working on a project in Groovy/Grails and being stuck *not* having gone to the conference for the amazing technical content and great networking.

Hope to see you there! (If you see me, please say “hi”) – I’ll be the jetlagged one drinking too much Red Bull 🙂

Written by peterbell

April 30, 2010 at 12:20 pm

Posted in Conferences, gr8, Grails, Groovy

gr8 conference in the US on Friday

leave a comment »

I’m really looking forward to attending the gr8 conference in Minneapolis this Friday. I have been doing more and more Groovy and Grails projects recently and am looking forward to get to know the broader US community (the Copenhagen conference last year was great – but there weren’t that many US attendees).

I’ll be writing an article for Groovy Mag on the conference, so if you are presenting and would like to be interviewed briefly, I’ll be in the conference hotel Thursday evening and all day Friday (I’m flying back to NYC first thing Saturday) so make yourself known (a tweet to @peterbell is probably the easiest option) and I look forward to meeting you!

Written by peterbell

April 14, 2010 at 5:56 pm

Posted in Conferences, gr8, Grails, Groovy

The Gr8 Conference: The Grails Plug-in System – Plug in to Productivity

with one comment

After Graeme’s talk on building a Twitter clone in Grails, we took a short break and then returned to another presentation by Graeme – this time on the process of writing plug-ins for Grails. The core message of this presentation was that you don’t need to be a Grails guru to write plug-ins. Even if you’re just writing applications for your own use, you should consider using plug-ins to modularize them.

Grails Plugins
Grails is designed to wire together different libraries and to make them easy to use. Out of the box, Grails uses plugins: controllers, gsp, GORM for Hibernate persistence. etc. In total there are  10-11 plug-ins in the default Grails applications you get when generating them using create-app to provide the core grails experience. In this sense, Grails can be seen as a “platform for runtime configuration”.

There is a Grails runtime with the concept of a grailsapplication (with a class that models that), along with an application content and then a bunch of plugins. For example the quartz plugin (for scheduling tasks) actually adds a new notion called a “job” to Grails to the grailsapplication object. So you can extend the grailsapplication object.

The Extension Points:
There are a number of different extension points that you can leverage when building a Grails plugin.
Build system – additional command line scripts.
Spring application context – for sensible defaults and configs. Spring has concept of message driven beans that plugins can auto configure.
Dynamic method registration – Adding methods automatically to certain classes of objects. For example, GORM adds save, list, delete and other persistence methods to domain objects.
Auto reloading – for example the JMS plugin listens for change events to services and reconfigures message driven bean on changes.
Container config (web.xml) – Grails generates the web.xml. Can participate in the generation
Adding new artifacts – Can add new artifacts and artifact types. New concept like a job in quartz, or just create controllers (like the searchable plugin does).

What is a Plugin?
– Just like a normal Grails project
– The only difference is the presence of a <pluginname>GrailsPlugin.groovy file
– Use “grails create-plugin [plug-in name]” to create one – that’s it!

A plugin is just a regular Grails project and can be developed like one.
The plugin descriptor:
class LoggingGrailsPlugin {
def version = 0.4
def dependsOn = [core: “1.0 > *”]

Packaging your Plug-in
It’s also easy to package up a plugin:
grails package-plugin
cd ../my-project
grails install-plugin ../logging/
or remotely like:
grails install-plugin http://myserver/

Plugins and application modularity
Grails app plus . . .
– messaging, security, search, blog, wiki, maps, etc
All main app does is to provide a set of plugins

Adding Basic Artifacts
– A plugin can add new tag libs, controllers and services simply by creating them in the plugin project
– Since a plugin project is just like any project, you can just create and run one

Turning the twitter app into a plugin:
– Start by factoring out the domain into a plugin

grails create-plugin twitter-domain

Look at the TwitterDomainGrailsPlugin.groovy it creates

Copy domain to plugin and delete
Then cd into twitter-domain and grails package-plugin it

grails create-plugin twitter-iphone
grails install -domain ../twitter-domain/

add [dependson:TwitterDomain: “0.1” , iWebKit: “0.4”]

Note: When create plugin project, doesn’t auto install any of the grails plugins like Hibernate, so may need to grails install-plugin Hibernate – otherwise it’ll say “can’t find property “save””.

Note: dependencies are transitive, so install twitter-iphone, if it depends on iWebKit, it’ll install that automatically.

More advanced use cases (beyond the basics)
Can provide bean defs in def doWithSpring – e.g. setting “time to live” higher in production for EhCacheFactoryBean
See the Grails user guide for a description of the Spring Domain Specific Language
Plugins allow you to manipulate the underlying Spring context based on the environment, the conventions and the state of other plugins.

Can enhance behavior with doWithDynamicMethods to add to the application.domainClasses.each {} and then (for example_ domainClass.metaClass.constructor can be overwritten)
or add domainClass.metaClass.static.load = {long id -> template.load(delegate.getClass() , id)}
See the metaprograming guide on the Groovy website.

There are some issues re: template rendering and static resources in plugins, so they do require just a little more thought than an app – but not much.

Plugins already available
– Test: Selenium, fitnesse, code coverage, etc
– Rich Grails: Flex, GWT, GrailsUI (YahooUI), etc
– Secure Grails: Spring, JSecurity, OpenID, etc
– Integrate Grails, Search, Jasper Reports, JMS, etc

Check them out at – can comment, search, etc.

– Plugins are crucial to the grails story
– Everyone is a plugin developer – not just the gurus
– Plugins help to create modular applications
– Plugins automate configuration through convention over configuration

Written by peterbell

May 21, 2009 at 5:37 pm

Posted in gr8, Grails

The Gr8 Conference: Building a Twitter Clone in Grails (or why Grails rocks!)

with 2 comments

The second day of the gr8 conference kicked off with a great presentation by Graeme Rocher on Building Twitter in Grails. Rather that giving a blow by blow of the presentation, you should check out a similar earlier presentation he gave yourself. The online presentation is close enough to the one Graeme gave to be better than my written notes. What I do want to do is comment very briefly about why I was so impressed by the presentation.

For anyone following languages and frameworks, it’s pretty easy to get jaded by all the “build an X in Y minutes” presentations. With a little bit of ORM and scaffolding, it’s pretty easy to write a framework that will let you build a simple blog in ten minutes with postings and comments (I wrote my own in two weeks in ColdFusion including extensible model and controller description in XML, a custom data mapper/baby-ORM and lightweight DI/IoC engine – it’s not a terribly hard problem to solve). What really stands out with Grails is that you can get a system with caching and a JMS message queue with transactional capabilities in under an hour!

As I mentioned in my recent GroovyMag article, the real differentiator for Grails (apart from the very simple learning curve for Java developers) is access to proven enterprise Java plumbing under the hood, with Groovy/Grails primarily being a “lipstick layer” to allow you to use Java frameworks without having to put up with the explicit configuration, static typing and lack of dynamic language features.

In an hour, Graeme demonstrated the creation of a simple Twitter client. He implemented a nice AJAX interface for posting and updated, implemented Security using the acegi plugin which wraps Spring (nee acegi) Security, added caching using ehcache, search (with the searchable plugin) using Lucene and Compass, JMS messaging for clearing the cache asynchronously with transactional integrity, and the capacity to access the page using .json or .xml file extensions and he even added a feed plugin to give you an rss feed in just a few lines of code!

Clearly any such demonstration is tied to the strengths of the framework being demonstrated, but it really showed me just how quickly you could mock up an enterprise style app that you could then just add richness to as required to (say) tie into legacy databases or more complex authentication systems. An incredibly impressive demonstration of a very compelling framework!

The sample code from the conference USB stick doesn’t quite work out of the box. You have to bootstrap a default role. In the grails-app/config/Bootstrap.groovy add:

def init = { servletContext ->
new Authority(authority:”ROLE_USER” , description:”Default User Role”).save()

and I’m also running into issues with null pointers for the twitter cache (conf/spring/resources.groovy – line 3: twitterCache(org.springframework.cache.ehcache.EhCacheFactoryBean))

however, I’ll have a look at this (I have a feeling anyone with Grails experience would figure this out in about 2 minutes, and I’m pretty sure I’ll be able to figure it out when I get a spare half hour to look at it – hopefully this weekend) and will post a slightly modified version of the code so anyone can download and play with the app. You *should* try this at home – it rocks! Kudos to Graeme & the Grails team!

Written by peterbell

May 21, 2009 at 1:16 pm

Posted in gr8, Grails

Picking an IDE for Grails Development

with 3 comments

I’ve been using Eclipse for a while now for most of my development (with Textmate as a backup when I don’t want to fire up an entire IDE). However, coming to the Grails world recently it was pretty clear that the Groovy Eclipse plugin wasn’t really ready for prime time. There are some notes on using it for Grails development, but it didn’t seem to me to be a viable option for Grails development.

I looked for a while at using Netbeans for Grails development. When I first started looking, it appeared to be a non starter, but with the fairly recent announcements of version 6.5+ support for Grails it has become a much more credible contender. It doesn’t have debugging, support for GSPs and there can be performance issues, but if you’re in the market for an IDE, the price is right (free!) and I’d definitely recommend giving it a shot.

In the end, I decided to go with IntelliJ. I bought a license for 8.1. As a personal developer it’s $250 for a license, but if I do even one project in Grails and it saves me a morning it’ll have paid for itself. It’s the IDE that most of the core team seem to use, and while there have been some complaints about IntelliJ choking on Grails 1.1 projects (especially with global plugins) I think they’re going to continue to invest in keeping this as the premier IDE for Groovy/Grails development.

If I change my mind, I’ll certainly let you know! What do you think? What IDE did you choose (if any) and why? I’d also be interested to hear from anyone using Textmate or vi (I don’t speak to emacs people 🙂 – kidding!). Have you ever used an IDE? Were you already a long time text editor afficianado or did you choose to move because you felt (for instance) that the benefits of an IDE were less in a dynamic language (limitations on code completion, etc.)?

Written by peterbell

March 26, 2009 at 2:26 pm

Posted in Grails, IDEs