Latest jQuery with Grails 2 and the resources plugin

von Florian Mutter

We just updated the front end of an older Grails 2.1.5 application to Bootstrap.

The application uses the resources plugin and due to some other dependencies the jQuery plugin is loaded. The jQuery plugin ships with jQuery 1.11.1 and was not updated since 2014. The latest jQuery version as of now is 2.2.3. So how can we update the javascript library without fiddling with dependency excludes or other hacks?

The resources plugin lets you override single resource files that are loaded in a plugin. The only thing you need is the id of the resource. In this case we have the following definition in the Grails jQuery plugin:

modules = {
    'jquery' {
        resource id: 'js',
                 url: [plugin: 'jquery', dir: 'js/jquery', file: "jquery-${jqver}.min.js"],
                 disposition: 'head', nominify: true
    }
    [...]
}

The id for the javascript file is 'js'. The new jQuery version was put in web-app/lib/jquery-2.2.3. With the following override in the ApplicationResources.goorvy configuration the latest jQuery version is used everywhere:

modules = {
    overrides {
        'jquery' {
            resource id: 'js', url: 'lib/jquery-2.2.3/jquery-2.2.3.js'
        }
    }
    [...]
}

This is a simple and fast way to override any javascript or css file that is provided by a Grails plugin. The documentation of the resources plugin has some more informations about overrides.

Kategorien: GrailsJavaScriptResponsive Design

Zurück