【发布时间】:2021-10-15 19:04:29
【问题描述】:
有一个库,即io.github.elye:simplekotlinlibrary,版本为 1.0.0、2.0.0 和 3.0.0。
io.github.elye:easyandroidlibrary:1.0.0 包含io.github.elye:simplekotlinlibrary:1.0.0
io.github.elye:simpleandroidlibrary:2.0.0 包含io.github.elye:simplekotlinlibrary:2.0.0
所以在我的 Gradle 中,如果我有的话
implementation ('io.github.elye:easyandroidlibrary:1.0.0')
implementation ('io.github.elye:simpleandroidlibrary:2.0.0')
implementation ('io.github.elye:simplekotlinlibrary:3.0.0')
对于包含传递依赖项的项目,它将自动解析为io.github.elye:simplekotlinlibrary:3.0.0。
但是,对于https://docs.gradle.org/current/userguide/dependency_constraints.html#sec:adding-constraints-transitive-deps,它声明constrains 还会强制将依赖项升级到指定的版本3.0.0。
implementation ('io.github.elye:easyandroidlibrary:1.0.0')
implementation ('io.github.elye:simpleandroidlibrary:2.0.0')
implementation ('io.github.elye:simplekotlinlibrary')
constraints {
implementation('io.github.elye:simplekotlinlibrary:3.0.0') {
because 'testing force upgrade'
}
}
根据我的理解,以上两个例子会产生相同的结果。好像constraint 没有实际用处? constraint 与不同的自动依赖解析有何不同?
【问题讨论】:
标签: gradle dependencies constraints gradle-dependencies