A Gradle version conflict happens when two dependencies transitively require different versions of the same library, and Gradle's default "highest version wins" strategy picks one that breaks compatibility somewhere. Resolving it means identifying the conflict and explicitly telling Gradle which version to use.
Key Points: • Use gradle dependencyInsight --dependency <name> --configuration <configName> to see every path bringing in the conflicting library and which version wins by default. • Force a specific version project-wide using resolutionStrategy.force in the configurations block. • Alternatively, use a dependency constraint to declare a preferred version without forcing it on every module. • Exclude a specific transitive dependency from a module with exclude group: '...', module: '...' if it should never be pulled in from that path. • After forcing a version, re-run the build and tests to confirm the forced version is actually compatible with all consumers.
Example: Two libraries in a project transitively required different versions of okhttp; dependencyInsight showed the conflict clearly, and adding resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.12.0' resolved it by forcing a single consistent version across the build.
Code Example:
configurations.all {
resolutionStrategy {
force 'com.squareup.okhttp3:okhttp:4.12.0'
}
}Interview Tip: A concise interview answer is:
"I'd run dependencyInsight to see exactly which dependencies are pulling in conflicting versions, then use resolutionStrategy.force, or a dependency constraint, to pin a single compatible version project-wide. After forcing the version I'd rerun the full test suite to make sure nothing that depended on the older version broke."