如何强制特定依赖项在Gradle中使用特定版本的库 [英] How can I force a specific dependency to use specific version of a library in gradle

查看:351
本文介绍了如何强制特定依赖项在Gradle中使用特定版本的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖项'com.liferay.mobile:liferay-screens:2.1.4',我想强制使用例如'com.android.support:support-v4:28.0.0'.如何仅对gradle中的 liferay-screens 依赖项强制执行此操作?

I have a dependency 'com.liferay.mobile:liferay-screens:2.1.4' and I want to force it for example to use 'com.android.support:support-v4:28.0.0'. How can I do this force only for liferay-screens dependency in gradle?

我已经按照下面的方法完成了,但是会出错:

I've done it like below but it takes error:

<代码>错误:在类型为org.gradle.api.internal的对象上,找不到参数com.liferay.mobile:liferay-screens:2.1.4()的方法[build_e4u81lzxji4bi1lau20a1sng2 $ _run_closure3 $ _closure7 @ 2be4e1d1].artifacts.dsl.dependencies.DefaultDependencyHandler.

implementation 'com.liferay.mobile:liferay-screens:2.1.4' {
    resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
}

推荐答案

在Gradle 6.0中,我的建议是使用新的

In Gradle 6.0, my recommendation would be to use the new strictly semantics in a constraint:

dependencies {
    implementation 'com.liferay.mobile:liferay-screens:2.1.4'
    constraints {
        implementation('com.android.support:support-v4') {
            version {
                strictly '28.0.0' // Will make sure that library uses that version in your build
            }
        }
    }
}

在Gradle 6.0之前,您的方式将是推荐的方式,但是语法需要进行调整:

Prior to Gradle 6.0, your way would be the recommended one, but the syntax needs to be adapted:

dependencies {
    implementation 'com.liferay.mobile:liferay-screens:2.1.4'
}
configurations.all {
    // Will force that dependency version everywhere
    resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
}

在您尝试表达的情况下,强制仅在给定上下文中的 版本实际上没有意义.重要的是,您希望总体分辨率始终使用该特定版本.

There is effectively no point in forcing a version only in a given context, as you tried to express. What matters is that you want to overall resolution to always use that specific version.

这篇关于如何强制特定依赖项在Gradle中使用特定版本的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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