我的gradle项目使用该application插件来构建一个jar文件.作为运行时传递依赖的一部分,我最终会进入org.slf4j:slf4j-log4j12.(它被引用为至少5或6个其他传递依赖的子传递依赖 - 这个项目使用spring和hadoop,所以除了厨房水槽之外的所有东西都被拉进来......没等了......那也是:) ).
我想slf4j-log4j12从我的内置jar中全局排除jar.所以我试过这个:
configurations {
runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)
但是,这似乎排除了所有 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).
Run Code Online (Sandbox Code Playgroud)
我不想查找每个slf4j-log4j12传递依赖的源,然后compile foo { exclude slf4j... }在我的dependencies块中有单独的语句.
更新:
我也试过这个:
configurations {
runtime.exclude name: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)
最终排除了构建中的所有内容!好像我指定的那样group: "*".
更新2:
我正在使用Gradle版本1.10.
Jen*_*s D 120
啊,以下工作并做我想要的:
configurations {
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)
似乎排除规则只有两个属性 - group和module.但是,上述语法不会阻止您将任意属性指定为谓词.尝试从单个依赖项中排除时,您无法指定任意属性.例如,这失败了:
dependencies {
compile ('org.springframework.data:spring-data-hadoop-core:2.0.0.M4-hadoop22') {
exclude group: "org.slf4j", name: "slf4j-log4j12"
}
}
Run Code Online (Sandbox Code Playgroud)
同
No such property: name for class: org.gradle.api.internal.artifacts.DefaultExcludeRule
Run Code Online (Sandbox Code Playgroud)
因此,即使你可以指定一个依赖group:,并name:不能与指定排除name:!?!
也许是一个单独的问题,但究竟什么是模块呢?我可以理解groupId:artifactId:version的Maven概念,我理解它转换为group:name:Gradle中的版本.但是,我如何知道特定Maven工件属于哪个模块(以gradle-speak方式)?
小智 34
要全局排除一个或多个库,请将以下内容添加到build.gradle中
configurations.all {
exclude group:"org.apache.geronimo.specs", module: "geronimo-servlet_2.5_spec"
exclude group:"ch.qos.logback", module:"logback-core"
}
Run Code Online (Sandbox Code Playgroud)
现在,排除块有两个属性组和模块.对于那些来自maven背景的人,group与groupId相同,模块与artifactId相同.示例:要排除com.mchange:c3p0:0.9.2.1以下应该是排除块
exclude group:"com.mchange", module:"c3p0"
Run Code Online (Sandbox Code Playgroud)
Pet*_*ser 28
你的方法是正确的.(根据具体情况,您可能希望使用configurations.all { exclude ... }.)如果这些排除实际上排除了多个依赖项(我在使用它时没有注意到),请在http://forums.gradle.org上提交一个错误理想情况下,有一个可重复的例子.
BER*_*ine 16
在下面的例子我排除
弹簧引导起动的tomcat
compile("org.springframework.boot:spring-boot-starter-web") {
//by both name and group
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
Run Code Online (Sandbox Code Playgroud)
pet*_*ula 10
compile已弃用并被替换为implementation. 因此,对于那些运行较新版本的 gradle 的人来说,解决方案是:
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 spring boot 1.5.10 并尝试排除 logback,上面给定的解决方案效果不佳,我改用配置
configurations.all {
exclude group: "org.springframework.boot", module:"spring-boot-starter-logging"
}
Run Code Online (Sandbox Code Playgroud)
除了@berguiga-mohamed-amine 所说的之外,我刚刚发现通配符需要将模块参数保留为空字符串:
compile ("com.github.jsonld-java:jsonld-java:$jsonldJavaVersion") {
exclude group: 'org.apache.httpcomponents', module: ''
exclude group: 'org.slf4j', module: ''
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
99787 次 |
| 最近记录: |