对于以下依赖:
compile(group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17')
覆盖传递依赖版本的常用方法是这样的:
configurations.all {
resolutionStrategy {
// add a dependency resolve rule
eachDependency { details ->
if (details.requested.name == 'xmlbeans') {
details.useVersion '3.1.0'
}
}
}
}
它有效。但它需要 2 个断开连接的 groovy 代码块。 6 个月后的开发人员必须有足够的经验才能知道去其他地方寻找相关逻辑。
更具可读性的是在直接依赖的范围内覆盖传递依赖。我想像这样:
compile(group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17') {
eachDependency { details ->
if (details.requested.name == 'xmlbeans') {
details.useVersion '3.1.0'
}
}
}
Gradle 对象模型似乎应该支持这种逻辑,但在 Google 上搜索却出奇地困难。是否有可能?如果是这样,块会是什么样子?
我知道有一个子 exclude
节点和一个单独的非嵌套 compile
节点。但随后 gradle 依赖树(我的组织在第三方库审计中非常依赖它)表明存在直接依赖,而实际上并没有。