2017-02-10 61 views
0

我們正在面對與Storm 1.0.1和elasticsearch 5.2的gradle中的sl4j版本衝突。sl4j版本與Storm 1.0.1和elasticsearch的Gradle衝突5.2

我們發現ElasticSearch需要橋接log4j-to-slf4j,以便我們可以使用所需的記錄器。 這裏我們試圖用slf4j來使用logback-classic。

的依賴定義如下:

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

要解決此我試圖排除風暴核心的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中找到綁定.class] 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 at org.apache.logging.log4j.spi.LoggerRegistry.getOrCreateInnerMap(LoggerRegistry.java :140) at org.apache.logging.log4j.spi.LoggerRegistry.hasLogger(LoggerRegistry.java:154) at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:38) at org.apache .logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger (AbstractLoggerAdapter.java:47) at org.apache.logging.slf4j.Log4jLogg erFactory.getLogger(Log4jLoggerFactory.java:29) 在org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)

回答

0

由於異常狀態,有含StaticLoggerBinder.class兩瓶。

  • /Users/gauthamr05/Documents/Apps/Storm/apache-storm-1.0.1/lib/log4j-slf4j-impl-2.1.jar
  • /用戶/ gauthamr05 /文檔/工作區/ xyz_app/build/libs/FullIndexing.jar

問題:xyz_app/build/libs/FullIndexing.jar是您自己的項目之一嗎?

如果它是您自己的jar,我在這裏猜測一下,但我猜org/slf4j/impl/StaticLoggerBinder.java被封裝在classpath中的一個jar中。有一個奇怪的默認值javac,它將編譯您的類路徑中的jar中找到的任何.java文件。這可以通過

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

被關閉參見herehere

0

發現了一種陰影在最終罐子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*" 
}