Grails Less CSS Plugin

Recently, the LessCSS project was ported from Ruby to Node (JavaScript). This makes my implementation of the plugin obsolete. Please checkout David Marquis’ Blog for a much nicer Rhino implementation. I’m keeping this post here for historical purposes.

If you use CSS and think it might be one of the most needlessly complex parts of web development (as I do), Less CSS might be worth taking a look at. It’s been described as “CSS 4 from the futurez!” and, after using it on a few small projects, I really like it.

While some really cool projects exist to help integrate Less into your specific platform (check out .less for .NET projects, for a great OS X front end app, and Less for Java as just a handful of examples), there didn’t exist anything yet for Grails.

Enter the Grails Less CSS plugin! As of right now, the plugin is in a very alpha state and works as follows:

  • Install the plugin (see below).
  • Place your .less files in the webapp/css directory (where your .css files would go)
  • Reference style sheets in your HTML as if the less files had a .css extension (e.g. a main.less file would be in your header as main.css).
  • Whenever a .less file changes, the associated .css file will be refreshed as well.

The Good

  • The plugin uses the Asual (see above) Java library which, in turn, uses JRuby to run the original Ruby project. The good thing about this approach is that this plugin can easily keep pace with the Ruby project and incorporate the latest features and bug fixes.
  • There is no longer any need to checkin .css files to your source repository as these can be considered “scratch” files that are easily regenerated from the .less source (similar to .groovy and .class files: the .groovy file is the one that really matters).

The Bad

  • Currently, the plugin pulls the entire JRuby library into the project. This adds some resource overhead and, although it’s fast once it gets running, it adds an approximate 3 second load time to the project.
  • There is no differentiation (yet) between development and production environments. As such, the plugin continues to run as part of the application in, say, a WAR deployed on Tomcat even though there is (probably) no reason for it to. I’m working on fixing this in a future update.
  • Less files that fail to properly compile generate really nasty stack traces and crash Grails. The messages are accurate and help diagnose the error, but it would be better to handle the exceptions in a better way (this is coming soon as well).


The plugin hasn’t yet been approved as a bonafide Grails plugin by the plugin community. Until then, visit the Github repository and download the (or whatever the latest version is) file. After it is downloaded, type

grails install-plugin [plugin]

This is a work in progress, so feel free to give me some feedback and check out the source on Github!


About johnnywey

Welcome to A Regular Expression. This blog is designed to reflect my thoughts on life, music, software design, Apple, faith, philosophy, and whatever else I can think of.

Posted on March 2, 2010, in CSS, Grails, Java, Programming. Bookmark the permalink. 2 Comments.

  1. Right on, Johnny! Looks great!

  2. Hey that’s awesome. I always felt this functionality was lacking in CSS and knew there had to be a better solution.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: