SGT Grumpy Pants
SGT Grumpy Pants

Reputation: 4436

Grails: Conditionally Load Spring Security LDAP Plugin

I have an app that runs in multiple production environments. In one environment we want to authenticate with LDAP, in the other we do not. If the Spring Security LDAP plugin is included in BuildConfig.groovy, the non-LDAP environment fails to authenticate because LDAP is not configured.

I tried

environments {
    devldap {
        plugins {
            compile ":spring-security-ldap:2.0-RC2"
        }
    }
}

but the LDAP plugin still builds with the non-LDAP environment and causes the non-LDAP environment (in this case development) to fail to authenticate if I don't include the LDAP configuration because it can't connect to LDAP.

I've tried

grails clean
grails refresh-dependencies

but the LDAP plugin only uninstalls if I completely comment it out.

How can I conditionally include/exclude a plugin in my build?

Upvotes: 0

Views: 158

Answers (1)

I Stevenson
I Stevenson

Reputation: 844

I see this question is a bit old now, however I do a similar thing with the Melody plugin. There is no value in this being installed during TEST - and can get in the way - so I do the following:

plugins {
    // other plugins ...

    if( Environment.current != Environment.TEST )
        compile ":grails-melody:1.56.0"

    // other plugins ...
}

So when I run 'test-app' I see the plugin 'uninstalled' and then when I do 'run-app' I see it installed and it's available.

NOTE: I recently got caught out by forgetting to also do an import grails.util.Environment. If you do that, you'll find that Environment.current == [:] as does Environment.TEST etc. I believe this is due to the builder behind the config file.

Upvotes: 1

Related Questions