从gradle的多个依赖项中排除同一组? [英] Excluding the same group from multiple dependencies in gradle?

查看:802
本文介绍了从gradle的多个依赖项中排除同一组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android项目的应用模块中的build.gradle中包含以下代码

I have the following code in the build.gradle in the app module of my Android project

implementation('com.google.firebase:firebase-core:16.0.1', {
    exclude group: 'com.android.support'
})
implementation('com.google.firebase:firebase-database:16.0.1', {
    exclude group: 'com.android.support'
})
implementation('com.google.firebase:firebase-auth:16.0.1', {
    exclude group: 'com.android.support'
})
implementation('com.google.firebase:firebase-crash:16.0.1',  {
    exclude group: 'com.android.support'
})

firebase库都包含我正在使用的android支持库的冲突版本,因此我需要将其排除以防止生成警告

The firebase libraries all contain a conflicting version of the android support library which I am using and so I need to exclude it to prevent the build warning

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

有没有一种方法可以将这些实现语句组合在一起,所以我只需要编写一个排除语句?

Is there a way I can group these implementation statements together so I only need to write one exclude statement?

编辑

我基于Cris回答的具体解决方案

My specific solution based on Cris' answer

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'com.android.support') {
            details.useVersion '27.1.1'
        }
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-crash:16.0.1'
}

推荐答案

如官方

As stated on the official gradle documentation, you can achieve that as follows:

configurations {
    implementation {
        exclude group: 'javax.jms', module: 'jms'
        exclude group: 'com.sun.jdmk', module: 'jmxtools'
        exclude group: 'com.sun.jmx', module: 'jmxri'
    }
}

另一种选择是在这种情况下强制使用一组特定版本的库. 官方文档

Another option, is to force a specific version of the group of libraries, support in this case. This is also covered by the official documentation

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'org.gradle') {
            details.useVersion '1.4'
            details.because 'API breakage in higher versions' 
            //note that details.because requires Gradle version 4.6 or higher
        }
    }
}

这篇关于从gradle的多个依赖项中排除同一组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆