本文將介紹如何在 Gradle 中排除掉指定的依賴蛙紫。
Gradle 3.4 及以下版本
在 Gradle 3.4 及以下版本拍屑,我們引入依賴的方式還是通過 compile
,如:
dependencies {
compile 'org.apache.commons:commons-lang3:3.4'
compile project(':common:util')
testCompile 'junit:junit:4.12'
}
想要移除掉某個(gè)依賴中的模塊坑傅,我們通常會(huì)這么做:
dependencies {
compile('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections', module: 'commons-collections'
}
// 不指定 module
compile('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections'
}
}
Gradle 3.4 及以上版本
升級(jí)到 Gradle 3.4+ 之后僵驰,Gradle 支持了默認(rèn)的新的引入依賴的方式: implementation
:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
關(guān)于 compile
和 implementation
的區(qū)別可移步至 whats-the-difference-between-implementation-and-compile-in-gradle 查看詳情。
全局排除依賴
全局排除指定環(huán)境的依賴
configurations {
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
compile.exclude group: "org.slf4j", module: "slf4j-log4j12"
}
全局排除所有環(huán)境下的依賴
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
相關(guān)鏈接: