Gradle如何排除依赖项目的某些包

在开发一个Gradle相关项目时,遇到了Gradle如何排除依赖项目的某些包这个问题,网上也并不能找到相关问题的解决方案,这就让我需要我仔细阅读官方文档相关部分了。
官方文档描述如下:
若要为配置声明特定的依赖项,可以使用以下语法:
dependencies {
configurationName dependencyNotation
}
要在声明依赖项时对其执行一些高级配置,还可以传递一个配置闭包:
dependencies {
configurationName(dependencyNotation){
configStatement1
configStatement2
}
}
案例:
plugins {
id 'java' // so that I can declare 'implementation' dependencies
}
dependencies {
implementation('org.hibernate:hibernate:3.1') {
//in case of versions conflict '3.1' version of hibernate wins:
force = true
//excluding a particular transitive dependency:
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
//disabling all transitive dependencies of this dependency
transitive = false
}
}
项目依赖语法:
configurationName project(':some-project')
可是上面只说了项目依赖,包依赖,和包排除依赖的例子,根本没有说明如何排除项目依赖里面的包啊。具体可见:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html
思考捣鼓了半会,发现闭包可以解决这个问题
dependencies {
//使用闭包
implementation (project(path: ':vblog-server-common')){
// 排除项目依赖
exclude(group: 'com.github.pagehelper', module: 'pagehelper-spring-boot-starter')
exclude(group: 'org.springframework.boot', module: 'spring-boot-starter-data-redis')
}
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
}
搁这查看半天,发现是语法没入门,是时候该认真学习一下Groovy和查阅Gradle相关Api了


这篇博客介绍了如何在Gradle中排除某个项目依赖的特定包。作者在研究官方文档后,发现可以通过在依赖闭包中使用`exclude`方法来排除特定的组和模块。例如,`exclude(group:'com.github.pagehelper', module:'pagehelper-spring-boot-starter')`。通过这种方式,可以解决版本冲突或减少不必要依赖的问题。作者提醒读者,深入学习Groovy和Gradle DSL对于理解和解决问题至关重要。
2340

被折叠的 条评论
为什么被折叠?



