grantmcconnaughey
grantmcconnaughey

Reputation: 10689

Adding Spring Security dependency to Grails plugin

I am developing a Grails 2.2.3 plugin for internal use, and in the plugin I would like to have the configured security settings that I use in every app. Spring Security config, Spring Security LDAP config, and custom UserDetails class and UserDetailsContextMapper class.

I have all of that taken care of, but the issue I'm having is that I cannot get the dependencies to work correctly in the plugin. It works fine if the app using the plugin into declares spring-security-core and spring-security-ldap in its plugin dependencies, but apps shouldn't have to declare this dependency - the plugin should take care of it.

So how do I get this plugin to install and use the spring-security-core and spring-security-ldap plugins correctly? Here is my BuildConfig.groovy file in the plugin:

    plugins {
        compile ":spring-security-core:1.2.7.3"
        compile ":spring-security-ldap:1.0.6"
        //Putting this in the app USING the plugin makes it work fine.
    }

Upvotes: 0

Views: 816

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

The plugins block is correct. If it's not working after installing from a zip, you might have some cruft left over from before.

To keep things in one place, I like to remove

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports" 

and replace them with

grails.project.work.dir = 'target'

so everything is under the target folder. When things get weird, run rm -rf target to force a full re-resolve and rebuild.

Then, rather than using inline plugins (which aren't great about transitive deps because we read that info from POM files now and that's not available unless you package the plugin properly) or zips, use the release plugin's maven-install script.

Add this to the plugins section (removing any older version you might have):

build ':release:2.2.1', ':rest-client-builder:1.0.3', {
   export = false
}

and after running grails compile to get it resolved, the maven-install script will be available. This packages your plugin and copies it to the right place in your $HOME/.m2/repository folder. Then if you add or uncomment mavenLocal() in the repositories block in your application's BuildConfig.groovy, you can just add a dependency for your plugin in your application as if it were released in the main repo, e.g.

plugins {
   compile ':my-cool-security-plugin:0.1'
}

Re-run grails maven-install periodically when you make changes to the plugin, and delete the target directory to force a reinstall in the app.

Upvotes: 2

Related Questions