在使用Gradle时如何排除传递依赖的所有实例? [英] How do I exclude all instances of a transitive dependency when using Gradle?
问题描述
我的gradle项目使用应用程序
插件来构建一个jar文件。作为运行时传递依赖的一部分,我最终得到了 org.slf4j:slf4j-log4j12
。 (它在至少5或6个其他传递依赖中被称为子传递依赖 - 这个项目使用spring和hadoop,所以除厨房水槽以外的所有东西都被拉进来......不等待......那里也是:) )。
我想从我的内置jar中全局排除 slf4j-log4j12
jar。所以我试过了:
配置{
runtime.exclude group:org.slf4j,name: slf4j-log4j12
}
然而,这似乎排除了所有 org.slf4j
包括 slf4j-api
的工件。在调试模式下运行时,我看到如下行:
org.slf4j#slf4j-api被排除在com.pivotal.gfxd :gfxd-演示的MapReduce:1.0(运行时)。
org.slf4j#slf4j-simple从com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(运行时)中排除。
org.slf4j#slf4j-log4j12从org.apache.hadoop中排除:hadoop-common:2.2.0(运行时)。
我不想查找每个 更新: 我也试过这个: 最终排除构建中的一切!就像我指定 更新2: 我为此使用Gradle 1.10版本。 下面的工作,并做我想要的: 看来排除规则只有两个属性 - 与 所以即使你可以用 也许是一个单独的问题,但 完全是模块<那么?我可以理解groupId的Maven概念:artifactId:version,我知道它翻译为Gradle中的group:name:version。但是,那么,我怎么知道一个特定的Maven工件属于哪个模块(在gradle中说)? My gradle project uses the I want to globally exclude the However, this seems to exclude all I do not want to have to look up the source of each Update: I did also try this: Which ends up excluding everything from the build! As though I specified Update 2: I'm using Gradle version 1.10 for this. Ah, the following works and does what I want: It seems that an Exclude Rule only has two attributes - with So even though you can specify a dependency with a Perhaps a separate question, but what exactly is a module then? I can understand the Maven notion of groupId:artifactId:version, which I understand translates to group:name:version in Gradle. But then, how do I know what module (in gradle-speak) a particular Maven artifact belongs to? 这篇关于在使用Gradle时如何排除传递依赖的所有实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! slf4j- log4j12
传递依赖关系,然后在我的依赖关系中有单独的
compile foo {exclude slf4j ...}
语句$ c
配置{
runtime.exclude名称:slf4j-log4j12
}
group:*
。
配置{
runtime.exclude组:org.slf4j,,模块:slf4j-log4j12
}
group
和 module
。但是,上述语法并不妨碍您将任意属性指定为谓词。当试图从个体依赖中排除时,你不能指定任意属性。例如,这会失败:
依赖关系{
compile('org.springframework.data:spring-data-hadoop -core:2.0.0.M4-hadoop22'){
exclude group:org.slf4j,name:slf4j-log4j12
}
}
$ b
没有这样的属性:name for class:org.gradle.api.internal.artifacts.DefaultExcludeRule
组指定一个依赖项:
和 name:
不能指定一个带有 name:
!?!
application
plugin to build a jar file. As part of the runtime transitive dependencies, I end up pulling in org.slf4j:slf4j-log4j12
. (It's referenced as a sub-transitive dependency in at least 5 or 6 other transitive dependencies - this project is using spring and hadoop, so everything but the kitchen sink is getting pulled in... no wait... that's there too :) ).slf4j-log4j12
jar from my built jar. So I've tried this:configurations {
runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}
org.slf4j
artifacts including slf4j-api
. When running under debug mode I see lines such as: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
transitive dependency and then have individual compile foo { exclude slf4j... }
statements in my dependencies
block.configurations {
runtime.exclude name: "slf4j-log4j12"
}
group: "*"
.configurations {
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}
group
and module
. However, the above syntax doesn't prevent you from specifying any arbitrary property as a predicate. When trying to exclude from an individual dependency you cannot specify arbitrary properties. For example, this fails:dependencies {
compile ('org.springframework.data:spring-data-hadoop-core:2.0.0.M4-hadoop22') {
exclude group: "org.slf4j", name: "slf4j-log4j12"
}
}
No such property: name for class: org.gradle.api.internal.artifacts.DefaultExcludeRule
group:
and name:
you can't specify an exclusion with a name:
!?!