Grails log4j版本与第三方java API冲突

时间:2012-04-04 15:43:31

标签: grails log4j

我必须使用Cisco的第三方Java API,它使用旧版本的Log4J,即1.1.3 当独立运行时,显然API工作正常,但是当从Grails(1.3.7)运行时,它在Log4j初始化期间崩溃并出现一些“未找到操作”异常。

如何解决此冲突?

这是BuildConfig实际插件,其中包含lib文件夹中的cisco lib。

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.plugin.location.'advoss-orm-core' = "../../../advoss-orm-core-grails-plugin/branches/ShahbazORMPlugin"

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        grailsPlugins()
        grailsHome()
        grailsCentral()

        // uncomment the below to enable remote dependency resolution
        // from public Maven repositories
        mavenLocal()
        mavenCentral()

        flatDir  name:"lib", dirs:"lib"
        //mavenRepo "http://snapshots.repository.codehaus.org"
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }
    dependencies {
        runtime('mysql:mysql-connector-java:5.1.16') {
            transitive = false
        }
        compile ':command:1.0',
                ':commons-codec:1.3',
                ':commons-httpclient:3.1',
                ':commons-logging:1.1.1',
                ':deltawing:1.0',
                ':deltaxml:1.0',
                ':isorelax:1.0',
                ':jhall:1.0',
                ':jing:1.0',
                ':junit-dep:4.9b2',
                ':marklogic-xcc:4.2.2',
                ':metadata-extractor:2.3.1',
                ':msv:1.0',
                ':resolver:1.0',
                ':saxon:9pe',
                ':tagsoup:1.2',
                ':xep:1.0',
                ':xmlunit:1.3'
    }
}

现在这里是包含上述插件的项目的构建配置,无法使用Log4j错误执行思科库调用:

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.plugin.location.'adv-provisioning-server' = "../../../adv-provisioning-server/branches/AlamSher_AdvProvisioningServer"
grails.plugin.location.'advoss-orm-core' = "../../../advoss-orm-core-grails-plugin/branches/ShahbazORMPlugin"
//grails.plugin.location.'advoss-trouble-ticket' = "../../../advoss-trouble-ticket-grails-plugin/branches/ShahbazTroubleTicketPlugin"

//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.distribution = {
    remoteRepository(id: "release", url: "http://192.168.0.2:8080/artifactory/plugins-release-local") {
        authentication username: "maven_user", password: "mav3nus3r"
    }
}

grails.project.dependency.resolution = {

    pom true

    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {

        mavenLocal()
        mavenCentral()
        mavenRepo "http://repository.codehaus.org"
        mavenRepo "http://download.java.net/maven/2/"

        grailsPlugins()
        grailsHome()
        grailsCentral()
    }

    dependencies {
        runtime('mysql:mysql-connector-java:5.1.16') {
            transitive = false
        }
        compile 'jaxfront:jaxfront-html:1.0',
                'jaxfront:jaxfront-pdf:1.0',
                'jaxfront:jaxfront-core:1.0',
                'advoss-voms:VomsWSClient:1.0',
                'com.lowagie:itext:2.1.7',
                'freemarker:freemarker:2.3.9',
//                'net.sourceforge.barbecue:barbecue:1.5-beta1',
//                'net.sf.jasperreports:jasperreports-fonts:4.0.0',
//                'net.sf.jasperreports:jasperreports-javaflow:3.7.5',
                'commons-httpclient:commons-httpclient:3.1',
                'commons-net:commons-net:20030805.205232'
//        compile('net.sf.jasperreports:jasperreports:4.0.1') {
//            transitive = false
//        }
        compile('net.sf.jasperreports:jasperreports:4.1.2') {
            excludes 'poi-ooxml', 'antlr', 'commons-beanutils',
                    'commons-collections', 'commons-logging',
                    'ant', 'mondrian', 'commons-javaflow',
                    'barbecue', 'xml-apis-ext', 'xml-apis',
                    'xalan', 'groovy-all', 'hibernate',
                    'saaj-api', 'servlet-api', 'xercesImpl', 'xmlParserAPIs',
                    'spring-core', 'bsh', 'spring-beans', 'jaxen',
                    'barcode4j', 'batik-svg-dom', 'batik-xml',
                    'batik-awt-util', 'batik-dom', 'batik-css',
                    'batik-gvt', 'batik-script', 'batik-svggen',
                    'batik-util', 'batik-bridge', 'persistence-api',
                    'jdtcore', 'bcmail-jdk14', 'bcprov-jdk14', 'bctsp-jdk14'
        }
    }

    plugins {
        compile ':jsecurity:0.4.1',
                ':message-digest:1.1',
                ':quartz:0.4.2',
                ':export:0.7',
                ':jquery:1.4.4.1',
                ':jquery-ui:1.8.2',
                ':xml-validator:0.1',
                ':advoss-orm-core:1.0.2.0',
        compile (':adv-provisioning-server:1.0.0.1') {
            excludes('commons-httpclient')
        }
        runtime(':jasper:1.2') { excludes 'jasperreports' }
    }
}

1 个答案:

答案 0 :(得分:1)

如果我理解正确,你就会遇到冲突的依赖。

假设使用此工件字符串从maven解析了第三方思科库:"com.cisco.foo"。你可以在BuildConfig.groovy的一部分之后添加一个闭包来排除Log4J传递依赖,如下所示:

dependencies {
  // ... other dependencies
  compile("com.cisco.foo") {
    excludes "log4j"
  }
}

这将有效地排除Cisco lib包含的Log4J 1.1.3。

编辑:如果JAR只在lib/而不是上面的位,IIRC你可以这样做:

dependencies {
  // ... other dependencies
  inherits("global") {
    excludes "log4j"
  }
}

在这种情况下,同样是lib/目录中的log4j 1.1.3,或者Cisco JAR是一个带有Log4J类的胖罐。后一种情况可能会非常棘手,如果是这样,你应该向你提出这个问题。