【问题标题】:How to limit max version of a transitive dependency如何限制传递依赖的最大版本
【发布时间】:2022-01-07 02:07:49
【问题描述】:

我有一个关于如何指定传递依赖的最大版本的问题。让我用一个例子来解释一下:

我的应用程序使用库 library-foo,问题是 library-foo 版本 3.0+ 引入了重大更改,我的应用程序还没有准备好。所以我在我的依赖项中声明它:

implementation 'com.example:library-foo:(,3.0)'

当我引入一个新的依赖项时,我的问题就出现了,比如说library-bar。该库引入了对library-foo的传递依赖

library-bar 5.0   -depends on-> library-foo 2.2
library-bar 5.5   -depends on-> library-foo 3.1

所以,添加新依赖后:

implementation 'com.example:library-foo:(,3.0)'
implementation 'com.example:library-bar:5.+'

我希望依赖解析足够聪明。 Gradle 包含 5.5 版本,在我的项目中引入了重大更改。

我知道我也可以限制 library-bar 的最大版本,但是在具有很多依赖项的项目中,声明我的麻烦库的最大版本(在本例中为 foo)强制其余依赖项适应这个。

有可能吗?

【问题讨论】:

    标签: android gradle android-gradle-plugin dependencies build.gradle


    【解决方案1】:

    你可以使用gradle的constraints:

    implementation 'com.example:library-foo:3.0'
    implementation 'com.example:library-bar:5.+'
    constraints {
      implementation('com.example:library-foo:3.0') {
        because 'Versions greater than 3.0 introduce bugs'
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      相关资源
      最近更新 更多