Gradle如何排除依賴項(xiàng)目的某些包
在開發(fā)一個Gradle相關(guān)項(xiàng)目時,遇到了Gradle如何排除依賴項(xiàng)目的某些包這個問題,網(wǎng)上也并不能找到相關(guān)問題的解決方案,這就讓我需要我仔細(xì)閱讀官方文檔相關(guān)部分了。
官方文檔描述如下:
若要為配置聲明特定的依賴項(xiàng),可以使用以下語法:
dependencies {
configurationName dependencyNotation
}
要在聲明依賴項(xiàng)時對其執(zhí)行一些高級配置,還可以傳遞一個配置閉包:
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
}
}
項(xiàng)目依賴語法:
configurationName project(':some-project')
可是上面只說了項(xiàng)目依賴,包依賴,和包排除依賴的例子,根本沒有說明如何排除項(xiàng)目依賴?yán)锩娴陌 >唧w可見:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html
思考搗鼓了半會,發(fā)現(xiàn)閉包可以解決這個問題文章來源:http://www.zghlxwxcb.cn/news/detail-528048.html
dependencies {
//使用閉包
implementation (project(path: ':vblog-server-common')){
// 排除項(xiàng)目依賴
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'
}
擱這查看半天,發(fā)現(xiàn)是語法沒入門,是時候該認(rèn)真學(xué)習(xí)一下Groovy和查閱Gradle相關(guān)Api了文章來源地址http://www.zghlxwxcb.cn/news/detail-528048.html
參考
- DependencyHandler - Gradle DSL Version 7.6
到了這里,關(guān)于Gradle如何排除依賴項(xiàng)目的某些包的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!