在单个编译依赖项的范围内更改传递依赖项版本

时间:2021-03-24 20:56:11

标签: gradle

我不想要的

对于以下依赖:

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 依赖树(我的组织在第三方库审计中非常依赖它)表明存在直接依赖,而实际上并没有。

0 个答案:

没有答案