grade 依赖关系坑记录

背景:

我们经常使用maven依赖的时候,经常会出现各种版本不统一的问题,尤其是Androidx出来之后,经常会有同一个类在不同包中出现的情况,这时就需要exclude掉不需要的模块,但是最近遇到一个奇怪的问题就是exclude之后,依赖关系仍然存在,研究了一下原因记录下来。

首先我们查看依赖关系的命令是

gradle dependencies

那么为了减少干扰信息,我们只关注debug依赖关系

gradlew dependencies --configuration debugRuntimeClasspath

大概的内容如下:

debugRuntimeClasspath - Resolved configuration for runtime for variant: debug
\--- project :callshow
     +--- xxx:xxx:1.1.4-debug
     |    +--- com.android.support:support-annotations:24.2.1 -> 27.0.2
     |    +--- com.android.support:palette-v7:24.2.1
     |    \--- com.android.volley:volley:1.0.0
     +--- oxxx:xxx:4.1.3-debug
     |    \--- org.alex:event:1.0.12-debug -> 1.1.2-debug
     |         \--- com.parse.bolts:bolts-tasks:1.4.0
     +--- orxxx:xxx:4.1.2-debug
     +--- com.xxx:xxx:1.0.23-debug
     |    +--- xxx:xxx:3.0.0-debug
     |    +--- oxxx:xxx:1.4.1-debug
     |    |    +--- com.xxx:xxx:flatbuffers:1.0.0
     |    |    +--- com.squareup.okhttp3:okhttp:3.3.1
     |    |    |    \--- com.squareup.okio:okio:1.8.0 -> 1.9.0
     |    |    \--- xxx:xxx:propreader:3.0.1-debug -> 4.0.0-debug
     |    +--- xxx:xxx:event:1.0.16-debug -> 1.1.2-debug (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.10 -> 1.3.21
     |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.21
     |              +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.21
     |              \--- org.jetbrains:annotations:13.0
     +--- xxx:xxx:listitem:debug-1.0.11
     +--- project :livewallpapertemplate

遇到的问题就是,我已经添加了依赖去除关系,但是support-v4就是无法去掉,无论如何查看依赖关系仍然存在。

    implementation("xxx.xxx.xxx:core:4.1.3"){
        exclude("com.parse.bolts", "bolts-tasks")
        exclude("com.android.support", "support-fragment")
        exclude("com.android.support", "support-v4")
    }

这个问题之前也遇到过,但是有很多方法可以替代过,一直没有详细的查看原因,今天正好有时间,就研究一下,发现根本原因是我当前的gradle文件中有另一个maven是依赖xxx.xxx.xxx:core的maven的,依赖关系如下:

     +--- xxx.xxx.xxx:core:4.1.3-debug
     |    \--- com.android.support:support-v4:26.1.0  
     +--- xxx.xxx.xxx:ui:4.1.2-debug
     |    \--- xxx.xxx.xxx:core:4.1.3-debug (*)

这时无论我在xxx:core中如何加入exclude都是不生效的,只有先将xxx:core工程exclude掉才可以。

    implementation("xxx.xxx.xxx:ui:4.1.2"){
        exclude("xxx.xxx.xxx", "core")
    }

很简单的一个问题,但是不深入研究一下就像一根刺一样让人很不舒服。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值