在使用Gradle时如何排除传递依赖的所有实例? [英] How do I exclude all instances of a transitive dependency when using Gradle?

查看:1613
本文介绍了在使用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(运行时)。

我不想查找每个 slf4j- log4j12 传递依赖关系,然后在我的依赖关系中有单独的 compile foo {exclude slf4j ...} 语句

更新:



我也试过这个:

 配置{
runtime.exclude名称:slf4j-log4j12
}

最终排除构建中的一切!就像我指定 group:*



更新2:



我为此使用Gradle 1.10版本。

解决方案

下面的工作,并做我想要的:

 配置{
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:!?!



也许是一个单独的问题,但 完全是模块<那么?我可以理解groupId的Maven概念:artifactId:version,我知道它翻译为Gradle中的group:name:version。但是,那么,我怎么知道一个特定的Maven工件属于哪个模块(在gradle中说)?

My gradle project uses the 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 :) ).

I want to globally exclude the slf4j-log4j12 jar from my built jar. So I've tried this:

configurations {
  runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}

However, this seems to exclude all 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).

I do not want to have to look up the source of each slf4j-log4j12 transitive dependency and then have individual compile foo { exclude slf4j... } statements in my dependencies block.

Update:

I did also try this:

configurations {
  runtime.exclude name: "slf4j-log4j12"
}

Which ends up excluding everything from the build! As though I specified group: "*".

Update 2:

I'm using Gradle version 1.10 for this.

解决方案

Ah, the following works and does what I want:

configurations {
  runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}

It seems that an Exclude Rule only has two attributes - 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"
  }
}

with

No such property: name for class: org.gradle.api.internal.artifacts.DefaultExcludeRule

So even though you can specify a dependency with a group: and name: you can't specify an exclusion with a name:!?!

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆