Getting Groovy (and Grails)

Explorations in Groovy and Grails Development

Archive for the ‘Conferences’ Category

Review of Gr8.eu 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

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

Getting Groovy: What’s Next after gr8conf?

leave a comment »

I had a great time at gr8conf earlier this week, and feel like I did a reasonable job of blogging a summary of the sessions (some more than others – sorry Griffon fans!) So, what’s next?

Well, I’m definitely going to be doing some more work in Groovy and Grails and I’ll continue to add my experiences to this blog (so remember to add it to your feed reader if you haven’t already!). I’ll also be posting some content on Domain Specific Languages that’s relevant to Groovy devs, and next week I’ll be doing a series on “Getting with Git” for Groovy/Grails developers who’ve noticed the trend and want to know how to kick their subversion habit and join us in the world of distributed vcs’s!

I had a great time meeting everyone at gr8conf this year, and look forward to seeing you all again next year!

Written by peterbell

May 21, 2009 at 7:04 pm

Posted in Conferences, gr8

The Gr8 Conference: Industrial strength Groovy

with one comment

Paul King presented the final session of the conference. He has worked on a number of fairly large, Agile projects using Groovy and Grails and wanted to share some thoughts on best practices for building large Groovy and Grails applications. (His slides are available online)

Topics
– Testing/mocking JUnit, TestNG, EasyB, Spock, Instinct, MockFor, Gmock, EasyMock
– DI: Spring, Guice
– Coverage: Cobertura
– Code STyle: CodeNarc, IntelliJ
– Duplication: Simian
– Documentation: GroovyDoc
– Builds: Ant, Gant, GMaven, Gradle, Hudson
– Modularization: Grapes, OSGi

Groovy
– Out of the box it runs junit3, junit4 (if in class path), testNG
– Check out GMock and also expandometaclass mocking in grails

Paul provided an introduction to the common testing and mocking frameworks including JUnit, TestNG, EasyMock and GMock. He also introduced Instinct – a test framework he’s done some work with, and then talked briefly about Spock and EasyB – two interesting frameworks for capturing and running functional/acceptance tests.

Spock vs EasyB
– Spock is a BDD inspired framework that gives devs tools to make their lives easier
– EasyB is a great way to capture requirements and build the acceptance tests
– EasyB scenarios can be stories, and can leave them blank to make them descriptive stories. Then start adding closure code and can put in selenium, etc

DI In Dynamic Languages

In static languages, Dependency Injection is almost essential to create testable code. Without it, hard coded references to “new” objects can’t be replaced (I suppose you could come up with work arounds using test-aware object factories, but really, DI is the way to go). In Groovy (and most other dynamic languages) there are a number of tricks you can use to get the ability to stub/mock out objects without using a DI framework. For example, the object.metaClass.Constructor can be overloaded to point to a specific instance or do something else, so you can get some of testability benefits of DI in Groovy without having to use Spring or Guice. That said, as projects get larger there are still real benefits to using a DI framework. Paul provided a quick overview of two of the most common Java DI frameworks – Spring and Google Guice.

He then went on to look at code coverage using Cobertura, suggested that 100% coverage is a “necessary but not sufficient condition” (I’ll agree that it’s not sufficient – whether 100% coverage of all of your code is necessary, I’ll leave for another time and place!).

He spent some time looking at the ability to enforce code styles with Code Narc (such as setting maximum lines per method or class) and some of the IDE capabilities of IntelliJ for improving the style of your code. His suggestion was that you should allow your code checking tool to break the build, but should only put rules you’re willing to enforce 100% – otherwise you’ll just get more and more warnings and genuine coding issues will get lost in the noise in the reports.

He also introduced a tool called Simian for checking your code base for duplication. It supports Groovy, is free for OSS projects, $99 (Australian) for a single user (with restrictions) or $499 (Australian) per project for larger teams.

He talked briefly about GroovyDoc (which for Java devs familiar with JavaDoc is pretty much what you’d expect), and then went on to look at using Groovy within Ant to script your Ant files, and using Ant within Groovy to fire off Ant scripts from Groovy. He also recommended Gant – a layer on top of the Groovy Ant builder (Ant uses XML config, so a builder is a natural way to script it in Groovy), discussed GMaven (a Groovy Maven wrapper) and Gradle which is focused on bringing the benefits of dependency management (think Maven or Ivy), but in a Groovier style.

Continuous Integration
An important part of any non-trivial project is CI – especially with dynamic languages where you have to rely more heavily on tests because the compiler catches many fewer errors. There are a number of different CI servers such as CruiseControl, Continuum and TeamCity (commercial), but Paul presented on Hudson which is my favorite as it’s free, widely used, and much easier to get started with and to configure than Cruise.

Hudson has:
– Gant plugin – Can invoke Gant build script as the main build setup
– Gradle plugin – Allows hudson to invoke Gradle build scripts as the main build step
– Grails plugin – to invoke Grails tasks as build steps
– Hudsons CLI and the Groovy shell – Have access to runtime in Groovy so can ask what plugins, what is state of info inside it, etc.

Paul also briefly discussed modularization using either Grapes or OSGi.

It was a great overview of the various elements of pulling together a professional set of tools for testing and building Groovy and Grails apps.

Written by peterbell

May 21, 2009 at 6:57 pm

The Gr8 Conference: What’s new in grails 1.1

with 4 comments

After Guillaume had provided us an introduction to Groovy, it was Graeme Rochers turn to introduce Grails and to provide information on the latest features in Grails 1.1(.1). Graemes deck wasn’t on the memory stick and I’m writing this on the ‘plane back to New York, so I’m writing this up from my notes and memory, so apologies in advance if I miss anything . . .

Graeme started off by giving us the number of downloads for Grails. In December of 2008, there were 86,000 downloads. To put that into context, Spring only got 90,000 downloads and Hibernate got 50,000 so while the penetration of Spring and Hibernate is clearly much greater, Grails is really starting to get some traction in terms of downloads. There are also now case studies for Wired, LinkedIn, Contegix, Tropicana, SAP and Sky (150 million visitors per month on six servers – and the eighth most responsive website in the UK, above sites like amazon.co.uk).

The main theme for Grails 1.1 is “making integrating grails into your ecosystem easier”.

Stand alone GORM
Firstly, GORM (the Groovy Object Relational Mapper – a productivity layer on top of Hibernate) is now available stand alone if you want to use it outside of grails applications.

With standalone GORM, you declare grails.persistence.Entity classes, so you might have:
package com.music
@Entity
class Album {
String name
Date releaseDate
static hasMany = [song]
}

And then you’d configure the settings using a gorm SessionFactory:
<gorm:SessionFactory
base-package=”com.music”
data-source-ref=”datasource”
. . .
</gorm:SessionFactory>

Plugin Enhancements
In Grails 1.1 there is now support for global plugins so you don’t need to install plugins for every single project if all of your projects use the same shared plugins. So you can now (for example):
grails install-plugin code-coverage –global

There is also support for transitive plugin installs. So, when you install a plugin, it automatically installs any dependencies of that plugin. Also, installing a plugin attaches metadata to the project, so if the project is checked out of svn/git, the plugins are auto-installed. There is also support for uninstalling plugins.

It’s also possible to scope plugins now, so (for example) you’d set your code coverage plugins not to run in production. You can scope plugins by environmen or by lifecycle and individual resources can also be excluded. It is also now possible to configure your own internal repositories for plugins. It is also possible to create direct links to plugin installs (rather than pulling them from a repository), supporting a workflow where you might be developing both plugins and your application simultaneously.

The core message was really that everyone should write plugins – they are a way to modularize your application and are very easy to develop. This was expanded on in a later presentation.

Testing Framework
In grails 1.0 there is little support for mocking out slow resources (such as database calls) for your unit tests. With 1.1 there is a mock api and framework for developing faster running tests. There is a mock implementation of GORM, controllers, command objects, etc. You “grails create-unit-test [name]”, and extend an artifact specific test harness.

Controller Enhancements
There are a number of controller enhancements relating to data binding, duplicate request handling and forwards/includes.

In terms of data binding, there are now more options for binding incoming request parameters to domain classes. For example, you can bind to collection types:
<g:textField name=”books[0].title” value=”the stand” />

You can also binding to a subset of properties:
person.properties[“firstName”,”lastName”] = params

There is also now support for duplicate request handling (to stop users from submitting the same form twice):
<g:form useToken=”true” />
the withForm method then does the rest:
withform {
// good request
}.invalidToken {
// bad request
}

The current request can now forward control to another action:
forward controller:”home” , action:”index”

or obtain the response of another action with an include:
def content = g.include(controller : “home”)

View Enhancements
There is also now support for using JSP tag libs within gsp’s.

Project/Build Enhancements
There is a new api to discover the properties of the current environment. For example, you might:

import grails.util.*
assert Environment.current == Environment.DEVELOPMENT

And inspect project metadata:
assert “1.1.1” == Metadata.current.getGrailsVersion()

Grails projects can now be Maven projects
mvn grails:create-pom
mvn grails:run-app
mvn package

Grails projects can also now be build with Ant and Ivy.

Additional Enhancements
There is now Spring namespace support in Grails. You can use any spring namespace in BeanBuilder:
xmlns aop:”http://www.springframework.org/schema/aop&#8221;
xmlns jee:”http://www.springframework.org/schema/jee&#8221;

Grails 1.1.1 now includes support for GAE. Persistence is via JDO/JPA using big table and there is a command line deploy. The process is something like:

grails create-app myapp
cd myapp
grails uninstall-plugin hibernate
grails install-plugin app-engine
grails set-version 1
grails app-engine package
APPENGINE_HOME/bin/appCfg.sh update .target/war

They are working on GORM JPA to make it work with app engine.

Graeme did a great job of introducing the latest enhancements to Grails in just an hour. If you want to know more about where Grails is going next, the roadmap is available at http://grails.org/roadmap.

Written by peterbell

May 20, 2009 at 5:35 pm

Posted in Conferences, gr8

The Gr8 Conference: What’s new in Groovy 1.6

with 4 comments

After Dierks presentation, Guillaume LaForge was up next, providing an overview of the features of Groovy 1.6(.3). He covered a lot of materials – much of which is contained in his recent InfoQ article.

Introducing Groovy
He started with a brief introduction to Groovy. It’s a dynamic language on the JVM, it provides a Meta Object Protocol which allows for meta-programming techniques such as intercepting method calls. It compiles down to byte code, it’s an open source Apache licensed project and has a relaxed grammar derived from Java 5 (most Java code is valid Groovy code). It borrows ideas from other dynamic languages such as Smalltalk, Pyton and Ruby, has Java 5 features out of the box (annotations, generics, static imports, enums, etc) and with a flat learning curve for Java devs and the ability to run on the Google App Engine (check out http://groovyconsole.appspot.com), it’s really quick and easy to get started with.

Groovy is fully OO (no primitives, so you can add methods to numbers and write things like 1.day just like you would in Ruby), there is a joint compiler with the capacity for resolving circular dependencies between Java and Groovy code, it supports Closures, properties (no getters/setters required), optional typing and BigDecimal arithmetic by default for floating point numbers. There are handy APIs for XML, JDBC, JMX, templating and Swing UI’s, a strong ability for writing business user readable Domain Specific Languages, syntax level “builders” and it supports easy operator overloading (if you want to write 10.meters + 20.kilometers, for example).

It supports lists “def numbers = [1,2,3,4]”, maps “def map = [FR: ‘France] , BE: ‘Belgium’]” and ranges “def allowed = 18..65”. It allows for regular expressions, and has GStrings which are interpolated strings which allow for placeholder variable replacements “Hello ${FirstName}”. Triple double-quotes also allow you to create multi-line strings without having to concatenate the strings as you would in Java.

One of the key features of Groovy is support for Closures. These are reusable and assignable code blocks (anonymous functions). So for instance, you could write:
def greet = {println “hello ${it}”}
greet(“Guillame”)

You can pass parameters to closures:
def greet = {string name -> println “Hello ${name}”}

and you can pass closures around:
def method(Closure c) { c(“Hello”)}
method(greet)

They take a bit of getting used to, but can provide a great deal of expressiveness in your code as you get the hang of how and where to use them.

One of Groovys other great features is a set of builders. For example, the following script uses a markup builder to generate HTML (it could also be used for XML):
def mkp = new MarkupBuilder()
mkp.html {
head {
title “Groovy in action”
}
body {
div(width: ‘100’) { p(class: ‘para’) {span: ‘best book ever’}}
}
}
}

Groovy 1.6
After providing a brief overview of Groovy, Guillaume then went on to introduce the key improvements in the recently released Groovy 1.6.

Firstly, it’s faster – both at runtime and at compile time. groovyc tests 3-5 times faster than the 1.5 compiler and with advanced call-site caching techniques, he’s seen 150-460% increases in performance over 1.5 (although obviously your milage will vary).

There are also syntax enhancements with support for multiple variable assignment:
def (a , b) = [1 , 2]

def lat , long
(lat , long) = geocode(‘Paris’)

(a,b) = [b,a]

If there are mismatches in the number of elements, extra elements on the left just aren’t assigned to anything. If there are less elements on the left, nulls are put into the additional values on the right hand side of the assignment operator.

With Groovy 1.6 there is also support for optional returns in if/else and try/catch blocks. So you could write:
def method() {if (true) 1 else 0}

Groovy 1.6 also provides full support for Java 5 annotations. It is the only dynamic language to provide this feature.

Compile time meta-programming
Meta-programming is the ability of a program to modify itself. Groovy 1.6 adds support for Abstract Syntax Tree (AST) transformations, which should allow us to get rid of a lot of boilerplate technical code.  Groovy supports two kinds of transformations: global transformations, and local transformations that are triggered by annotations.

Out of the box, Groovy 1.6 comes with annotations such as @Singleton, @Immutable, @Lazy, @Delegate, @Nawify, @Category and @Mixin. Each saves you from writing a bunch of boiler plate code and allows you to more clearly express the intent of your code. You can also add your own global or local ASTs. It’s a technique you want to use sparingly as it would be easy to introduce hard to track down bugs where certain combinations of annotations introduced errors when they were used together, but it’s a great technique to have and something I’m going to be playing with and writing about more on this blog.

Guillaume also reviewed a number of other enhancements that have been added to Groovy 1.6. We now have Grape – the “Groovy Advanced Packaging System” which helps you to distribute your applications without having to include dependencies. You just declare the dependencies with @Grab and it’ll get them from Maven or Ivy repositories. @Bindable makes it easier to do data binding in swing, and the swing console application can now be run as an applet, has code indent support, script drag and drop and the ability to add jars to the classpath from the IDE.

The ExpandoMetaClass DSL is another new feature that I’ll be covering in more detail on the blog, but briefly, it’s a DSL for changing the behavior of types at runtime. There is also the support for runtime mixins:
JamesBondVehicle.mixin FlyingAbility

In addition, Groovy 1.6 had JSR-223 bundled, so if you simply can’t get through the day without adding a little Python or PHP to your Groovy, it’s supported out of the box. There is also a JMX builder available (http://groovy.codehaus.org/groovy+jmxbuilder). Finally, the Groovy 1.6 JAR contains OSGi metadata and can be used in OSGi containers (http://groovy.codehaus.org/osgi+and+groovy).

With only on hour to both introduce Groovy and provide an overview of the new 1.6 features, it was a high level presentation, but it was a great introduction to the language and provided a good overview of the latest additions to the language.

Written by peterbell

May 20, 2009 at 5:31 pm

Posted in Conferences, gr8