sl4j版本在gradle中与storm 1.0.1和elasticsearch 5.2冲突

ztigrdn8  于 2021-06-21  发布在  Storm
关注(0)|答案(2)|浏览(383)

我们在gradle面临着sl4j版本与storm 1.0.1和elasticsearch 5.2的冲突。
我们发现elasticsearch需要桥接log4j-to-slf4j,以便使用所需的记录器。在这里,我们试图使用经典的logback与slf4j。
相关性定义如下:

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'org.apache.logging.log4j:log4j-to-slf4j:2.6.2'
    compile 'ch.qos.logback:logback-classic:1.1.10'
    provided ('org.apache.storm:storm-core:1.0.1') {
        exclude(group: 'org.slf4j', module: 'slf4j-api')
    }
    compile 'org.elasticsearch:elasticsearch:5.2.0'
    compile 'org.elasticsearch.client:x-pack-transport:5.2.0'
}

为了解决这个问题,我尝试从storm core中排除slf4j,并在稍后添加相同的内容,如下所示:

configurations.all {
    resolutionStrategy {
        eachDependency { DependencyResolveDetails dependencyResolveDetails ->
            final requestedDependency = dependencyResolveDetails.requested
            if (requestedDependency.group == 'org.slf4j' && requestedDependency.name == 'slf4j-api') {
                requestedDependency.setVersion "1.7.7"
            }
         }
    }
}

但是当提交拓扑时,我们得到错误:slf4j:class path包含多个slf4j绑定。slf4j:在中找到绑定[jar:file:/users/gauthamr05/documents/apps/storm/apache-storm-1.0.1/lib/log4j-slf4j-impl-2.1.jar/org/slf4j/impl/staticloggerbinder.class]slf4j:在中找到绑定[jar:file:/users/gauthamr05/documents/workspace/xyz\u app/build/libs/fullindex.jar/org/slf4j/impl/staticloggerbinder.class]slf4j:请参阅http://www.slf4j.org/codes.html#multiple_bindings 为了解释。slf4j:实际绑定的类型为[org.apache.logging.slf4j.log4jloggerfactory]exception,位于org.apache.logging.log4j.spi.loggerregistry.getorcreateinnermap(loggerregistry)的线程“main”java.lang.stackoverflowerr中。java:140)在org.apache.logging.log4j.spi.loggerregistry.haslogger(loggerregistry。java:154)在org.apache.logging.slf4j.slf4jloggercontext.getlogger(slf4jloggercontext)。java:38)在org.apache.logging.slf4j.log4jloggerfactory.newlogger(log4jloggerfactory。java:37)在org.apache.logging.slf4j.log4jloggerfactory.newlogger(log4jloggerfactory。java:29)在org.apache.logging.log4j.spi.abstractloggeradapter.getlogger(abstractloggeradapter。java:47)在org.apache.logging.slf4j.log4jloggerfactory.getlogger(log4jloggerfactory)。java:29)在org.slf4j.loggerfactory.getlogger(loggerfactory。java:277)

fivyi3re

fivyi3re1#

例外情况是,有两个jar包含 StaticLoggerBinder.class .
/users/gauthamr05/documents/apps/storm/apache-storm-1.0.1/lib/log4j-slf4j-impl-2.1.jar
/users/gauthamr05/documents/workspace/xyz\u app/build/libs/fullindexing.jar
问题:是吗 xyz_app/build/libs/FullIndexing.jar 你自己的项目?
如果这是你自己的jar,我猜一下,但我猜是的 org/slf4j/impl/StaticLoggerBinder.java 在类路径上的一个jar里。有一个wierd默认值 javac 它将编译任何 .java 在类路径的jar中找到的文件。可通过以下方式关闭

compileJava.options.compilerArgs << '-implicit:none'

看到这里和这里了吗

fzsnzjdm

fzsnzjdm2#

找到了在最终jar中隐藏log4j类的方法。
以下是配置:

apply plugin: 'com.github.johnrengelman.shadow'

subprojects {
    shadowJar
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.22'
    compile 'ch.qos.logback:logback-classic:1.1.10'

    compileOnly("org.apache.storm:storm-core:1.0.1") {
        exclude module: "log4j-slf4j-impl"
        exclude module: "slf4j-api"
        exclude module: "log4j-to-slf4j"
    }

    // ElasticSearch and X-Pack
    compile 'org.elasticsearch:elasticsearch:5.2.0'
    compile 'org.elasticsearch.client:x-pack-transport:5.2.0'

    compile 'org.apache.logging.log4j:log4j-api:2.7'
    compile 'org.apache.logging.log4j:log4j-core:2.7'
}

shadowJar {
    relocate 'org.apache.logging.log4j', 'gautham.elasticsearch.org.apache.logging.log4j'

    zip64 true
    transform(ServiceFileTransformer) {
        path = 'META-INF/vesta*'
    }

    manifest {
        attributes 'Implementation-Title': 'Storm Topology',
            'Implementation-Version': 1.0,
            'Main-Class': 'com.gautham.topology.StormTopology'
    }

    baseName = 'StormTopology'

    mergeServiceFiles()

    exclude "META-INF/*.SF"
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
    exclude "LICENSE*"
}

相关问题