// 定义一个数组,key为group,value为你需要锁定的版本
ext.conflicts = [
'org.springframework' : '5.1.10.RELEASE',
'org.springframework.boot' : '2.1.9.RELEASE',
'org.springframework.cloud' : '2.0.1.RELEASE',
'org.yaml' : '1.23',
// 将所有group为 io.netty 并且 module 不是 netty-tcnative-boringssl-static 的依赖版本设置为 4.1.48.Final
'io.netty ~ netty-tcnative-boringssl-static': '4.1.48.Final'
]
// 定义一个闭包,用于处理排除module逻辑
ext.conflictHelper = { String key ->
return key.contains(' ~ ') ? key.split(' ~ ') : [key, '']
}
// 定义一个闭包,用于处理依赖版本
ext.conflictProcessor = { requested, item, details ->
if (requested.group == conflictHelper(item.key)[0] && requested.module.name != conflictHelper(item.key)[1]) {
println requested.module.name + ":" + requested.group + ":" + requested.version + " -> " + item.value
details.useVersion(item.value)
}
}
allprojects {
...
//解决版本冲突
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
conflicts.each { item ->
conflictProcessor(requested, item, details)
}
}
}
}