Grails plugin dependency issues

Ran into a few problems with Grails plugin dependencies here are some solutions.

Applies to Stack

Grails 2.3.0, cache:1.1.1, asset-pipeline:1.0.4, mongodb:1.3.0, shiro:1.2.0, hibernate:, database-migration:1.3.5

Problem 1:

Conditions: Using cache:1.1.1

grails compile fails with error:

| Error Compilation error: startup failed:
Compile error during compilation with javac.
C:\Grails\MyProject\target\work\plugins\cache-1.1.1\src\java\grails\plugin\cache\web\filter\ error: package net.sf.ehcache.constructs.blocking does not exist
import net.sf.ehcache.constructs.blocking.LockTimeoutException;

Solution 1:

Add the following in the BuildConfig dependencies section (if mongodb is used by a plugin, this should go into plugin’s BuildConfig dependencies)

dependencies {
 compile "net.sf.ehcache:ehcache-core:2.4.6"

Verification 1:

Delete target/* from any plugin and project sources
grails compile

Problem 2:

Conditions: You are using shiro:1.2.0 + Servlet API v3.0. Shiro includes servelt-api 2.5 by default and is causing a conflict.

grails compile fails with error:

C:\Grails\MyProject\target\work\plugins\cache-1.1.1\src\java\grails\plugin\cache\web\ error: method does not override or implement a method from a supertype
C:\Grails\MyProject\target\work\plugins\cache-1.1.1\src\java\grails\plugin\cache\web\filter\ error: cannot find symbol
contentType = response.getContentType();

Solution 2:

To eliminate this problem, exclude servlet-api from Shiro for shiro-cas:

dependencies {
compile("org.apache.shiro:shiro-cas:1.2.2") {
excludes "servlet-api"

Verification 2:

Delete target/*
grails compile

Problem 3:

Conditions: You are using shiro:1.2.0 + mongodb:1.0.3 – hibernate: – database-migration:1.3.5 (ie hibernate and database-migration are not included)

grails compile fails with error:

| Error Fatal error during compilation org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\Grails\MyProject\target\work\plugins\hibernate-2.2.4\.\HibernateGrailsPlugin.groovy: 18: unable to resolve class org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport
@ line 18, column 1.
import org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport

IntelliJ IDEA 13 may also throw a “IDEA hook: Grails not found!” error.

This is due to a dependency of shiro on hibernate-2.2.4 api.

Soution 3:

runtime (":shiro:1.2.0") {
excludes "hibernate"

Verification 3:

Delete target/*
grails compile

One way to sort out such errors is to run the grails dependency-report and look for the jar file which causes the problem. Trace back from jar file to the actual included plugin or dependency and add the excludes in either dependencies section or plugins section appropriately.


The GAME Stack

The GAME stack

Alright, you know what LAMP stack is. You may have also heard about the MEAN stack (Mongo, Express, Angular, Node), that is gaining popularity. So many stacks are popping up and I wonder when we would get a stack overflow of stack names. The advantage of MEAN is, everything is javascript and your team needs to know only one language throughout. Good and Bad, I guess. Good because your team skillset is only one language. Bad because your team skillset may have just one language. Future of software is unpredictable and if/when Javascript goes out of favor, you and your team will be considered legacy.

While all-javascript is attractive, there is already a solid base built on the server side stacks, especially around security. I’m proposing a new stack name – GAME – Grails, AngularJS, MongoDB as all of them are equally impressive. Of course, nothing novel about this and this stack is already being used by many, but not many know that the ‘E’ stands for ‘Eh?’ pronounced with a Scottish accent. So when you use this stack, you get to tell your friends – “We use GAME in our company – Grails, AngularJS, MongoDB, Eh?” (perhaps with a quirkly smile).

Though Grails and AngularJS seem to compete on what they do, I prefer to keep some things on server-side, because Grails is a joy to code with configuration and business logic. The nice thing is AngularJS syntax is very much Grails-y. There are a few good online examples of using these two, but I didnt find a step-by-step quick start guide anywhere. So if you are planning to introduce AngularJS into your Grails projects, try these steps:


1. It is not really required to use angularjs grails plugin. You can directly use your preferred angular.js version
2. If you are using IntelliJ, enable the AngularJS plugin. This gives you intellisense for angularjs directives
3. You can use angularjs with both resources and asset-pipeline plugin. I am starting to prefer asset-pipeline plugin, because all dependencies are kept within js itself (instead of ApplicationResources.groovy). The asset-pipeline gsps are a bit simpler to use than the resources.

Step 1: BuildConfig.groovy

plugins {
runtime “:asset-pipeline:1.0.4”

Step 2: Asset-pipeline directories

grails refresh-dependencies will create grails-app/assets/* directories. Move your existing resources from web-app into this directory appropriately.

Step 3: Add angularjs library and application.js

grails-app/assets/javascripts/angular/angular-1.0.8.js //AngularJS library
grails-app/assets/javascripts/my-angular.js //My AngularJS code (controllers, unit test etc)
grails-app/assets/javascripts/application.js //Application.js that wires all JS libraries


In asset-pipeline, all dependencies can be declared within the js itself. Here is the application.js (the root of js files):

//=require jquery
//=require angular/angular-1.0.8.js
//=require angular/my-angular.js
//=require_tree views

Step 4: Update main.gsp layout page

The layouts, main.gsp is slightly different using asset tags.

… meta tags …
<asset:link rel=”shortcut-icon” href=”favicon.ico” type=”image/x-icon”/>
<asset:link rel=”apple-touch-icon” href=”apple-touch-icon.png” />
<asset:link rel=”apple-touch-icon” href=”apple-touch-icon.png” sizes=”114×114″/>

<asset:javascript src=”application.js” />
<asset:stylesheet href=”main.css”/>
<asset:stylesheet href=”mobile.css” />

<div id=”grailsLogo” role=”banner” style=”float: left”>
<asset:image src=”mylogo.jpg” alt=”MyLogo” height=”100″ />
%{–<img src=”${resource(dir: ‘images’, file: ‘grails_logo.jpg’)}” alt=”grails-logo” height=”100″/>–}%

Step 5: Add sample angularjs code:


function HomeController($scope) {
$scope.myDate = new Date();


<%@ page contentType=”text/html;charset=UTF-8″ %>
<html ng-app>
<meta name=”layout” content=”main”>

<div id=”page-body” role=”main”>
<div ng-controller=”HomeController” >

Step 6: Verify

Goto http://localhost:8080/app/angularsample/index