Hi Team,
Is there a way to traverse initial Dependency graph that is used by Gradle to perform it’s dependency resolution?
My use case : Let’s say I have large android app with multiple transitive dependencies (non-monolithic multi module architechture). Each transitive dependency is an individual gradle project having its own separate repository on github. I have a specific app navigation related dependency implemented by my organisation named “com.example.android:navigation:x.x.x”. This navigation dependency is used by multiple transitive dependencies of app inidividually. I am interested to find out which version of this navigation dependency is getting resolved in each resolved transitive dependency of app using script utilizing gradle api’s at app level.
Manual way of doing it would be :
Find out all resolved versions of transitive dependencies at app level.
Go to each transitive dependency github, clone it (if not cloned), and open gradle project in IDE.
Run ./gradlew :transitive-dependency:dependencyInsight --configuration debugRuntimeClasspath --dependency "com.example.android:navigation". This would give version of navigation dependency getting resolved in opened project I am about to execute the command.
Yes dependencyInsight on resolved version of a leaf project (resolved version is in app) gives all the information I need.
But lets say I have 50 leaf projects which for which I need to find out resolved version of navigation dependency in resolved version of leaf project. Manually, I will have to checkout to tag/commit corresponding to resoled version of each leaf project in app to get this information.
Lets say resolved version of navigation dependency in App is 2.1.1. But that does not mean that 2.1.1 of navigation dependency would be the resolved version individually for project leafOne and leafTwo in both v1.1.1 and v.1.2.1.
Can I write a script at app level (or) is there an automated way to find out which version of this navigation dependency is getting resolved individually in each resolved version of 50 leaf projects of app?
dependencyInsight on the Android “App” project is giving information about dependency resolutions of whole dependency graph of app.
As per previous example, Lets say leafOne is resolved to v1.2.1 in App project.
I am looking for navigation dependency resolution for leafOne v1.2.1 in it’s repo (Now App is not in picture). But I would like to get this information using a script at App level since v1.2.1 is resolved version of leafOne in App.
As mentioned, manual way of doing it would be to go to tag of v1.2.1 of leafOne project in its separate individual github repo on my local machine and execute “dependencyInsight” for navigation dependency. This would give me correct information but I cannot do it manually for all leaf projects of App.
So to answer your question : “Isn’t dependencyInsight only on the “App” project already giving you all information you are after?”
Answer : No.
I’m sorry if I have to ask again, but what info are you missing.
The output should show which version was requested by that project and to what it resolved after conflict resolution.
----App
|
------------ LeafOne-v1.1.1
|
------------------------ Navigation Dependency (v1.1.1) (Declared as direct dependency in LeafOne)
|
------------------------ Navigation Dependency (v1.1.2) (Coming in as transitive dependency to LeafOne)
|
------------ Navigation Dependency (v1.1.3) (declared as direct dependency in App)
From this dependency structure, going by highest version of a dependency as resolved dependency in a individual gradle project :
Resolved version of navigation dependency in App is v1.1.3 (Coming as direct dependency to App project)
Resolved version of navigation dependency in LeafOne project is is v1.1.2 (Coming as transitive dependency to leafOne project)
If I execute dependencyInsight in App project for navigation dependency with below command, output would be
com.example.android:navigation:1.1.3
\--- debugRuntimeClasspath of App
com.example.android:navigation:1.1.2 -> 1.1.3
\--- Transitive dependency of leafOne-v1.1.1
\--- leafOne-v1.1.1
\--- debugRuntimeClasspath of App
com.example.android:navigation:1.1.1 -> 1.1.3
\--- leafOne-v1.1.1
\--- debugRuntimeClasspath of App
Though looking at above output, It can be deduced that resolved version of navigation dependency in leafOne project would be 1.1.2 and in App would be 1.1.3, this way of writing parse logic on output can be prone to errors if Gradle changes it’s output format in future.
Hence I am looking to write a script at App project level that traverses App dependency graph and gives output as all resolved navigation version of all downstream dependencies along with App in their individual git projects.
First things first, it’s Björn, or Bjoern, not Bjorn.
writing parse logic on output can be prone to errors if Gradle changes it’s output format in future.
Yes of course, if this is not a one-shot thing, I’d not suggest parsing that task output.
But as you confirmed the information you want is available in the task output.
You might just have a look at its implementation to get a hang of how to get hold of the information.