问题
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:
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'
}
回答1:
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
}
}
}
}
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.
来源:https://stackoverflow.com/questions/58888295/how-can-i-force-a-specific-dependency-to-use-specific-version-of-a-library-in-gr