简体   繁体   English

如何强制特定依赖项在 gradle 中使用特定版本的库

[英]How can I force a specific dependency to use specific version of a library in gradle

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' .我有一个依赖'com.liferay.mobile:liferay-screens:2.1.4'并且我想强制它使用例如'com.android.support:support-v4:28.0.0' How can I do this force only for liferay-screens dependency in gradle?如何仅针对 gradle 中的liferay-screens依赖项执行此强制?

I've done it like below but it takes error:我已经像下面那样做了,但它出错了:

ERROR: Could not find method com.liferay.mobile:liferay-screens:2.1.4() for arguments [build_e4u81lzxji4bi1lau20a1sng2$_run_closure3$_closure7@2be4e1d1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

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

In Gradle 6.0, my recommendation would be to use the new strictly semantics in a constraint :在 Gradle 6.0 中,我的建议是在constraint中使用新的strictly语义

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
            }
        }
    }
}

Prior to Gradle 6.0, your way would be the recommended one, but the syntax needs to be adapted:在 Gradle 6.0 之前,建议采用您的方式,但需要调整语法:

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.重要的是您希望整体解决方案始终使用该特定版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM