当我们在做gradle多模块项目时,经常会在父模块中为子模块统一引入一些依赖,例如:
// 配置子工程
subprojects {
apply plugin: 'java'
// 指定编译版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
// 配置字符编码
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
//配置子模块依赖
dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.40'
}
}
但是有时候我们有些子模块可能不需要这个依赖,那我们就要排除它,怎么办呢?
正确操作如下:
plugins {
id 'java'
}
configurations.all {it ->
resolutionStrategy {
exclude group: 'com.alibaba.fastjson2', module: 'fastjson2'
}
}