$: ./gradlew :<your base module>:dependencies > dependencies.txt
$: # vim or nano `dependencies.txt`
$: vim dependencies.txt
$: # try to search the dependencies version used, to detect which transitive dependency making our build fails
If there's a problem with a specific version of your dependencies, try to search the version was pulled from which dependencies, e.g:
our current project dependencies has different version of
androidx.test:monitor
, see images
The above transitive dependencies might be failed due to a mismatch version, in this case the most left line of +---
indicating the root/dependency we used, and the | +---
means a child or transitive dependencies pulled from the parent dependencies :D and so on
TODO: update with red annotation in the images instead to give more clarity
Also the above cases was to summarize:
androidx.test.espresso:espresso-core:3.4.0-alpha04
we used, depends on (has transitive dependencies of) androidx.test:monitor:1.4.0-alpha04
+--- androidx.test.espresso:espresso-core:{require 3.4.0-alpha04; reject _} -> 3.4.0-alpha04 // parent
| +--- androidx.test:runner:1.4.0-alpha04 // pulled this deps 01
| | +--- androidx.annotation:annotation:1.0.0 -> 1.2.0 // pulled this 01A
| | +--- androidx.test:monitor:1.4.0-alpha04 // pulled this 01B
androidx.test:core:1.3.0
we used, depends on (has transitive dependencies of) androidx.test:monitor:1.3.0
+--- androidx.test:core:{require 1.3.0; reject _} -> 1.3.0 // parent
| +--- androidx.annotation:annotation:1.0.0 // pulled this deps 01
| +--- androidx.test:monitor:1.3.0 (*) // pulled this deps 02
Therefore, the espress-core
might resulting in a compiler error (due to fetching the alpha version), if that's the case, then we can go to below section to Force, Exclude or Strict our (transitive) dependencies instead
Maybe can also try this from GUI (Intellij IDEA based): https://www.jetbrains.com/help/idea/work-with-gradle-dependency-diagram.html#gradle_diagram I honestly didn't try it
If the build (even there's mismatch version) on our/your environment succeed, just skip the below approaches XD Because it'll bite you! If you insist to working on it, unless required to do (e.g: upgrade/refactor/migration process)
---------------- STOP FROM THIS ----------------
Or try to force specific version of gradle dependency to prevent mismatch version:
https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html
tl;dr:
Force transitive dependencies:
dependencies {
// httpclient has `commons-codec:1.10` as transitive dependency
// see: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.4
implementation("org.apache.httpcomponents:httpclient:4.5.4")
// but we requires to use `commons-codec:1.9`
// careful, doing this might breaking (if between 1.9 & 1.10 has a breaking changes when released)
// always check for their release notes, or even better for their API (build manually) :D
implementation("commons-codec:commons-codec:1.9") {
isForce = true
}
}
Exclude transitive dependencies:
implementation("com.squareup.retrofit2:retrofit:2.9.0") {
exclude(group = "com.squareup.okhttp3") // if we want to prevent retrofit fetching the `okhttp3:3.y.z`
because("version 3.x pulled from retrofit")
}
Strict version of specific dependencies:
implementation("com.squareup.okhttp3:okhttp:4.9.1") {
version { strictly("4.9.1") } // force this to use `4.9.1` as well
because("version 3.x pulled from Chucker, coil, picasso, retrofit")
}
More on what transitive dependency
is: https://docs.gradle.org/current/userguide/dependency_management_terminology.html#sub:terminology_transitive_dependency