我的Gradle项目使用application
插件来构建jar文件。作为运行时传递依赖项的一部分,我最终会拉入org.slf4j:slf4j-log4j12
。(它至少在5或6个其他传递依赖项中被引用为子传递依赖项 - 这个项目正在使用Spring和Hadoop,所以除了厨房水槽以外的所有东西都被拉进来了......等等,那也在里面 :) )。
我想要从构建的jar文件中全局排除slf4j-log4j12
jar。因此,我尝试了这个:
configurations {
runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}
然而,这似乎排除了org.slf4j
的所有工件,包括slf4j-api
。在调试模式下运行时,我会看到如下行:
org.slf4j#slf4j-api is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-simple is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-log4j12 is excluded from org.apache.hadoop:hadoop-common:2.2.0(runtime).
我不想要查找每个slf4j-log4j12
传递依赖项的源代码,然后在我的dependencies
块中使用单独的compile foo { exclude slf4j... }
语句。
更新:
我也试过这个方法:
configurations {
runtime.exclude name: "slf4j-log4j12"
}
这将导致构建中所有内容都被排除在外!就好像我指定了group:“*”
。
更新2:
我正在使用Gradle版本1.10进行此操作。
configurations { runtime.exclude group: '*' }
。 - sfdurbanomodule
。例如:exclude group: "org.apache.logging.log4j", module: "log4j-slf4j-impl"
。 - prayagupa