Grails, SpringSource And Clojure Thursday, July 30, 2009

I recently developed a Grails plugin which provides support for easily accessing Clojure code in a Grails app. The details of how the plugin works are covered at http://grails.org/plugin/clojure. That page includes a link to a brief video demonstration which is available at http://s3.amazonaws.com/jeffscreencasts/grails_clojure_demo.mov. Check it out.

Shortly after publishing the plugin I posted something about it on Twitter. Not too long after that a couple of other SpringSource folks tweeted about Clojure (here and here). I got a couple of questions (in jest I am sure) about SpringSource and Clojure. "Is SpringSource Moving To Clojure?". Of course not. SpringSource is not moving to Clojure. SpringSource is all about helping folks build serious applications for the JVM and most of that is done in Java. This is not news. I work on Groovy and Grails. Much of what I do is in Groovy. This too is not news. Making it easy for folks to use languages like Scala and Clojure while taking advantage of all the great stuff that Grails has to offer, that is appealing to me and that is why I developed the Clojure plugin.

Clojure is a really interesting language. There are others. The fact that 3 folks from SpringSource have expressed some kind of interest in Clojure shouldn't be all that surprising. There are probably even more folks at SpringSource who have some kind of interest in Clojure but for entertainment, lets focus on the 3 mentioned...

I am honestly not sure how many technologists work for SpringSource but for the sake of having a number to work with, lets say there are 50. Lets also say that Clojure is interesting enough that 15% of JVM developers are interested in learning more about it. I can't back that number up with any research, lets just go with it. If 15% of JVM developers are interested in the language and you take a random group of 50 JVM developers (the 50 in question are certainly not 50 random developers, these are the edge cutters which probably makes them more likely to be interested in keeping an eye on what is new, but work with the idea that they are random)... Do the math. No, really... Do the math. Do the math to figure out the likelihood that 3 of the 50 would be interested in Clojure. I challenge you to do the math in Clojure and post your solution in a comment here. Do it in Scala, Do it in Groovy. Pick a JVM language and do the math.

The simplest solution is probably not very interesting. Prefer a solution that shows off something interesting in your language of choice.

Hmmm... are you more likely to need to refer to the Clojure book, or the high school math book? ;)

Now, you have one more reason to tinker with a new language.

Enjoy.

Grails 1.1 beta3 Is Out! Thursday, January 29, 2009

We are closing in on the much anticipated release of Grails 1.1. Today beta 3 was released. See the release notes.

A new feature that has not been documented yet involves new validation capabilities. Up to this point, domain classes and command objects within a Grails app have supported really powerful validation capabilities. See section 7 in The User Guide for info on how that works. What is new is now you can apply those same validation capabilities to any class within a Grails app, not just domain classes and command objects. Making a class validateable involves defining a static property called "constraints" and assigning a closure, just like you would in a domain class or a command object.

Second, you have to tell Grails about your validateable class. You have 2 options for doing that. One option is to mark you class with the org.codehaus.groovy.grails.validation.Validateable annotation. Another option is to define your validateable classes in grails-app/conf/Config.groovy by assigning a value to the grails.validateable.classes property. That would look something like this...


grails.validateable.classes = [ com.mycompany.dto.SomeClass, com.mycompany.SomeOtherClass]


An annotated class might look something like this...


// src/groovy/com/companyname/SomeClass.groovy
package com.companyname

import org.codehaus.groovy.grails.validation.Validateable

@Validateable
class SomeClass {
Integer age
String name

static constraints = {
age range: 16..66
name blank: false, size: 5..35
}
}


Note that if you are using the annotation based approach, Grails will search all classes in the app to find all of the @Validateables. While that isn't really a performance problem, you can tune that a bit by specifying some specific packages that Grails should search. To do that, assign a value to grails.validateable.packages in grails-app/conf/Config.groovy like this...


grails.validateable.packages = ['com.companyname.dto', 'com.companyname.someotherpackage']


If the grails.validateable.packages property has a value then Grails will only look in those packages (and packages below those packages) for classes marked with @Validateable.

While this is still beta software, I think the feature will end up being delivered in the final release pretty much like it is described above. If you have any input on that or any other features in Grails. We would love to hear from you. Bring it to the mailing list or file a JIRA issue.

Enjoy!