sl4j版本与Storm 1.0.1和elasticsearch 5.2在gradle中发生冲突

时间:2017-02-10 06:10:53

标签: gradle apache-storm slf4j elasticsearch-5

我们正在与Storm 1.0.1和elasticsearch 5.2一起面对sl4j版本冲突。

我们发现ElasticSearch需要桥接log4j到slf4j,以便我们可以使用所需的记录器。 在这里,我们尝试使用logback-classic和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:类路径包含多个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中找到绑定。类]     SLF4J:在[jar:file:/Users/gauthamr05/Documents/workspace/xyz_app/build/libs/FullIndexing.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定     SLF4J:有关解释,请参阅http://www.slf4j.org/codes.html#multiple_bindings。     SLF4J:实际绑定的类型为[org.apache.logging.slf4j.Log4jLoggerFactory]     线程“main”java.lang.StackOverflowError中的异常         在org.apache.logging.log4j.spi.LoggerRegistry.getOrCreateInnerMap(LoggerRegistry.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)         at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)         在org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)

2 个答案:

答案 0 :(得分:0)

如异常所述,有两个包含StaticLoggerBinder.class的罐子。

  • /Users/gauthamr05/Documents/Apps/Storm/apache-storm-1.0.1/lib/log4j-slf4j-impl-2.1.jar
  • /Users/gauthamr05/Documents/workspace/xyz_app/build/libs/FullIndexing.jar

问题:xyz_app/build/libs/FullIndexing.jar是您自己的项目之一吗?

如果它是你自己的罐子,我在这里做了一些猜测,但我猜测org/slf4j/impl/StaticLoggerBinder.java被包装在你的类路径上的一个罐子里面。有一个奇怪的默认值javac,它将编译在类路径中的jar中找到的任何.java文件。这可以通过

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

请参阅herehere

答案 1 :(得分:0)

找到一种方法来遮蔽最后一个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*"
}