0

我有一个在多个生产环境中运行的应用程序。在一种环境中,我们希望使用 LDAP 进行身份验证,而在另一种环境中,我们不需要。如果 BuildConfig.groovy 中包含 Spring Security LDAP 插件,则非 LDAP 环境无法进行身份验证,因为未配置 LDAP。

我试过了

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

但是 LDAP 插件仍然使用非 LDAP 环境构建,如果我不包含 LDAP 配置,则会导致非 LDAP 环境(在本例中development)无法进行身份验证,因为它无法连接到 LDAP。

我试过了

grails clean
grails refresh-dependencies

但 LDAP 插件只有在我完全注释掉它时才会卸载。

如何有条件地在我的构建中包含/排除插件?

4

1 回答 1

1

我看到这个问题现在有点老了,但是我用 Melody 插件做了类似的事情。在测试期间安装它没有任何价值 - 并且可能会妨碍 - 所以我执行以下操作:

plugins {
    // other plugins ...

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

    // other plugins ...
}

因此,当我运行“test-app”时,我看到插件“已卸载”,然后当我执行“run-app”时,我看到它已安装并且可用。

注意:我最近因为忘记做一个import grails.util.Environment. 如果你这样做,你会发现,Environment.current == [:]等等Environment.TEST。我相信这是由于配置文件背后的构建器。

于 2015-08-12T23:56:27.277 回答