sl4j版本与Storm 1.0.1和elasticsearch的Gradle冲突5.2
我们正在面对与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.*Error 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)
由于异常状态,有含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'
发现了一种阴影在最终罐子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*"
}