将Spring Security Rest插件添加到BuildConfig.groovy时,编译Grails 2.4.2应用程序时出错

时间:2017-08-14 15:20:48

标签: grails spring-security grails-2.4 spring-security-rest

我有一个使用Spring Security Core的 Grails 2.4.2 应用程序,我正在尝试使用身份验证来实现Restful API。为此,我在BuildConfig.groovy文件中添加了 Spring Security Rest v1.5.4 作为插件,如下所示:



    grails.servlet.version = "2.5"
    grails.tomcat.nio=false
    grails.project.class.dir = "target/classes"
    grails.project.test.class.dir = "target/test-classes"
    grails.project.test.reports.dir = "target/test-reports"
    grails.project.work.dir = "target/work"
    grails.project.target.level = 1.6
    grails.project.source.level = 1.6
    grails.project.war.file = "target/${appName}.war"
    grails.project.dependency.resolver = "maven" // or ivy
    grails.project.dependency.resolution = {
        inherits("global") {
        }
        log "info" 
        checksums true
        legacyResolve false
        repositories {
            inherits true

            mavenCentral()
            grailsPlugins()
            grailsHome()
            mavenLocal()
            grailsCentral()
            mavenRepo "http://repository.codehaus.org"
            mavenRepo "http://repo.spring.io/milestone/"
            mavenRepo "http://repo.grails.org/grails/libs-releases-local"
            mavenRepo "http://repo.grails.org/grails/core"
            mavenRepo "http://repo.spring.io/libs-snapshot"

        }

        dependencies {
            compile('com.lowagie:itext-rtf:2.1.7')
            compile('org.codehaus.groovy.modules.http-builder:http-builder:0.7') {
                excludes "commons-logging", "xml-apis", "groovy", "xercesImpl"
            }
            compile 'net.sf.ehcache:ehcache-core:2.4.8'

            test("org.seleniumhq.selenium:selenium-firefox-driver:2.41.0")
            test "org.gebish:geb-spock:0.9.2"

            compile 'org.grails.plugins:events:1.0.0.M1'
            compile 'org.springframework:spring-core:4.0.5.RELEASE'
            compile 'org.springframework:spring-context:4.0.5.RELEASE'
            compile 'org.springframework:spring-beans:4.0.5.RELEASE'
            compile 'commons-beanutils:commons-beanutils:1.8.3'
            compile ('eu.medsea.mimeutil:mime-util:2.1.3'){
                excludes([group:'org.slf4j', name:'slf4j-log4j12', version: '1.5.6'])
            }
            compile ('org.apache.poi:poi:3.10.1'){
                 excludes "xml-apis", "xercesImpl", "stax-api"
            }
            compile ('org.apache.poi:poi-ooxml:3.10.1'){
                 excludes "xml-apis", "xercesImpl", "stax-api"
            }
            compile ( group:'org.springframework.cloud', name:'spring-cloud-starter-eureka', version:'1.0.0.M2', changing: true){
                excludes "logback-classic", "xercesImpl", "tomcat-embed-core", "tomcat-embed-el", "stax-api", "hibernate-validator", "log4j-over-slf4j"
            }
            compile ('com.netflix.ribbon:ribbon-eureka:2.0-RC9'){
                excludes "xercesImpl",  "stax-api"
            }
            compile ('com.netflix.ribbon:ribbon-loadbalancer:2.0-RC9'){
                excludes "xercesImpl",  "stax-api"
            }
            provided ('xerces:xercesImpl:2.9.1'){
                excludes "xml-apis", "stax-api"
            }
            compile 'br.com.caelum.stella:caelum-stella-core:2.1.2'
            compile ('br.com.caelum.stella:caelum-stella-boleto:2.1.2'){
                excludes('itext')
            }
        }

        environments {
            test {
                dependencies {
                    runtime 'org.springframework:spring-test:3.2.9.RELEASE'
                    compile "commons-codec:commons-codec:1.9"
                }
            }
            production{
                dependencies {
                    runtime 'org.springframework:spring-test:3.2.9.RELEASE'
                    compile "commons-codec:commons-codec:1.9"
                }
            }
            development {
                dependencies {
                    runtime 'org.springframework:spring-test:3.2.9.RELEASE'
                    compile "commons-codec:commons-codec:1.9"
                }
            }
        }

        plugins {
            test ":geb:0.9.2"
            build ":tomcat:7.0.54"
            compile ":scaffolding:2.1.2"
            compile ':cache:1.1.7'
            compile ":rest:0.8"
            compile ':spring-security-core:2.0-RC3'
            compile ":spring-security-rest:1.5.4"
            compile ":mail:1.0.6"
            compile ':mongodb:3.0.3'
            compile ":ckeditor:4.4.1.0"

            runtime ":jquery:1.11.0.2"

            compile ':console:1.4.2'
            compile ":asset-pipeline:1.9.9"
            compile ":sass-asset-pipeline:1.9.1"
            compile ":mongodb-create-drop:1.0"
            compile (":export:1.6"){
                excludes "xml-apis", 'itext', 'itext-rtf', "xercesImpl", "stax-api"
            }
            compile (":rendering:1.0.0")
            compile ":br-validation:0.3"
            compile ":google-analytics:2.3.3"
            compile ":cache-headers:1.1.7"
            compile ":jslint:0.6"
        }
    }

执行run-app命令时,会显示以下错误:

    Compiling 279 source files
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: /tmp/groovy-generated-68181663753307402-java-source/grails/plugin/springsecurity/rest/token/AccessToken.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
      [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      [groovyc] /home/aescobar/IdeaProjects/lasa-portal-fornecedores/portal-web/target/work/plugins/spring-security-rest-1.5.4/src/groovy/grails/plugin/springsecurity/rest/token/storage/TokenStorageService.groovy: -1: The field 'instanceEventsApi' is not 'public static final' but is defined in interface 'grails.plugin.springsecurity.rest.token.storage.TokenStorageService'.
      [groovyc]  @ line -1, column -1.
      [groovyc] /home/aescobar/IdeaProjects/lasa-portal-fornecedores/portal-web/target/work/plugins/spring-security-rest-1.5.4/src/groovy/grails/plugin/springsecurity/rest/oauth/OauthUserDetailsService.groovy: -1: The field 'instanceEventsApi' is not 'public static final' but is defined in interface 'grails.plugin.springsecurity.rest.oauth.OauthUserDetailsService'.
      [groovyc]  @ line -1, column -1.
      [groovyc] 2 errors
    | Compiling 279 source files.
    | Error Compilation error: startup failed:
    /home/aescobar/IdeaProjects/lasa-portal-fornecedores/portal-web/target/work/plugins/spring-security-rest-1.5.4/src/groovy/grails/plugin/springsecurity/rest/token/storage/TokenStorageService.groovy: -1: The field 'instanceEventsApi' is not 'public static final' but is defined in interface 'grails.plugin.springsecurity.rest.token.storage.TokenStorageService'.
     @ line -1, column -1.
    /home/aescobar/IdeaProjects/lasa-portal-fornecedores/portal-web/target/work/plugins/spring-security-rest-1.5.4/src/groovy/grails/plugin/springsecurity/rest/oauth/OauthUserDetailsService.groovy: -1: The field 'instanceEventsApi' is not 'public static final' but is defined in interface 'grails.plugin.springsecurity.rest.oauth.OauthUserDetailsService'.
     @ line -1, column -1.
    2 errors

2 个答案:

答案 0 :(得分:0)

您可以尝试从spring-security-core插件中排除spring-security-rest吗?可以这样做:

 compile ":spring-security-rest:1.5.4", {
     excludes: 'spring-security-core'
 }

或者尝试使用这些插件的不同版本:对我而言,spring-security-core:2.0-RC4spring-security-rest:1.5.0.M2(提及排除)的组合效果很好。

答案 1 :(得分:0)

首先,感谢所有试图帮助我的人。

我发现问题是依赖项spring-security-rest:1.5.4org.grails.plugins:events:1.0.0.M1库冲突。

我真的不需要使用这个特定的事件库,所以我只是从我的项目中删除它。现在,一切都按照预期运作。

谢谢。