我们正在和gradle一起运行一个弹簧引导应用程序。
为了包含spring启动插件,我们将其作为依赖项添加:
buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE")
}
}不幸的是,这个插件附带了对org.apache.logging.log4j:log4j-slf4j-impl:2.4.1的依赖
我想排除。
已经尝试过了,添加了:
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE") {
exclude group: 'org.apache.logging.log4j'
}
}这不起作用。
还补充说:
configurations {
classpath.exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}没有任何效果。
任何暗示都欢迎。
发布于 2016-01-27 14:43:23
不知何故,问题在于我将log4j声明为运行时依赖关系:
ext {
log4jVersion="2.5"
}
runtime (
"org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion",
"org.apache.logging.log4j:log4j-api:$log4jVersion",
"org.apache.logging.log4j:log4j-core:$log4jVersion"
)这就导致了版本2.4.1是由某种编辑器魔术获取的编译依赖的情况。
因此,我有2.4.1和2.5的类路径。
当我将log4j声明为编译依赖关系2.4.1时,.
发布于 2016-01-27 13:20:36
如果你想排除
org.apache.logging.log4j:log4j-slf4j-impl:2.4.1试一试
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE") {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}
}发布于 2016-01-27 14:50:49
两个步骤,追逐传递依赖,然后将其排除在负责任的库中。
gradle dependencies给出了包括传递项在内的完整列表。如果您的项目很小,这可能会有帮助,但对于大型企业的构建..。信息太多了。可以随意搜索,但是我们可以从dependencyInsight获得更多的信息。
gradle dependencyInsight --dependency someDependency找到依赖项可能进入构建的所有位置。如果您有多个版本,这将有助于明确版本的来源。
在我的usecase中,日志记录被显式声明为编译时依赖项,因此如下所示。如果log4j在其他地方,您将看到违规的库以及v2.5的编译时声明。
我必须在每个子模块上显式地运行这个程序。
$ gradle util:dependencyInsight --dependency org.apache.logging.log4j
Configuration on demand is an incubating feature.
:util:dependencyInsight
org.apache.logging.log4j:log4j-api:2.5
+--- compile
\--- org.apache.logging.log4j:log4j-core:2.5
\--- compile
org.apache.logging.log4j:log4j-core:2.5
\--- compile
(*) - dependencies omitted (listed previously)
BUILD SUCCESSFUL
Total time: 0.933 secs现在,一旦您知道在哪里排除依赖项,只需像以前一样删除它。您可以通过再次运行dependencyInsights来确认
dependencies {
// found through `gradle dependencyInsight --dependency org.apache.logging.log4j`
classpath("someOtherGroup:someOtherArtifactId:1.0") {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}
}另一种解决方案可能是重写依赖项解析器并将版本强制为2.5。
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == "org.apache.logging.log4j") {
println "Updating version for: $details.requested.group:$details.requested.name:$details.requested.version --> 2.5"
details.useVersion '2.5'
}
}
}我的观点是,我可能不想一直在resolutionStrategy中添加检查,所以最好在dependencyInsights中跟踪它。此外,这意味着在两个地方更新版本,如果另一个开发人员不知道gradle的resolutionStrategy如何工作,那么他们就会有“奇怪”的行为.例如:我将log4j更新为2.7,但它仍然使用2.5?!
但这两种方法都是有效的
https://stackoverflow.com/questions/35038027
复制相似问题