1

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

我该如何解决这种冲突?

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

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'
    }
}

现在这里是包含上述插件的项目的构建配置,并且无法执行 Cisco 库调用并出现 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' }
    }
}
4

1 回答 1

1

如果我理解正确,您将遇到相互冲突的依赖关系。

假设第三方 Cisco 库是使用此工件字符串从 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 类的胖 jar。后一种情况可能更棘手,如果是这样,您应该将其添加到您的问题中。

于 2012-04-06T19:17:52.627 回答