autonomousapps / autonomousapps/dependency-analysis-gradle-plugin

Expose usage report as part of dependency analysis

Open
#1,637 1 comment 0 reactions 1 assignee Claimed by @autonomousapps View on GitHub
enhancement help wanted
Dominant language
Kotlin
Stars
2.2k
Forks
158
Avg merge
16h 25m
Merged PRs (30d)
46

Description

**Is your feature request related to a problem? Please describe.**

I would like to be able to get a report around dependency usages per Gradle module and a summary for the whole project. These reports would
- Provide a signal around module complexity
- Capture most frequently used APIs
- Enable a way to track migrations such as RxJava -> Coroutines

I'm including an example report that I generated using intermediary types already generated by this plugin
```json
{
"module": ":instacart-flyers:public",
"summary": {
"dependencyTypes": 6,
"dependencyTypeUsages": 10,
"internalTypes": 4,
"projectDependencies": 2,
"libraryDependencies": 3
},
"internal": {
"com.instacart.client.flyers.eligibility.ICFlyersBadgeFormula$DefaultImpls": 1,
"com.instacart.client.flyers.eligibility.ICFlyersBadgeState$Companion": 1,
"com.instacart.client.flyers.eligibility.ICFlyersBadgeFormula": 1,
"com.instacart.client.flyers.eligibility.ICFlyersBadgeState": 1
},
"projectDependencies": {
":instacart-analytics:public": {
"com.instacart.analytics.latency.ICPageKey": 3
},
":instacart-global-home-tabs:public": {
"com.instacart.client.ui.pages.ICTabFeature": 2
}
},
"libraryDependencies": {
"com.instacart.formula:formula": {
"com.instacart.formula.IFormula": 2,
"com.instacart.formula.IFormula$DefaultImpls": 1
},
"com.instacart.formula:formula-android": {
"com.instacart.formula.android.RouteKey": 1
},
"io.reactivex.rxjava3:rxjava": {
"io.reactivex.rxjava3.core.Observable": 1
}
}
}
```

**Describe the solution you'd like**

This plugin is already doing deep usage analysis to be able to determine if a dependency is used or not. The ideal solution would provide first-class APIs to get access to this usage data. There are a couple of options here:
- Generate a first-class usage report similar `advise.json`
- Provide an extension API that provides direct access to the data models. The user can generate any kind of report using the data.

**Regarding the implementation:**
- To generate report, we need access to `ProjectVariant` and `Dependencies` types to generate the r
- There already exists `ComputeUsagesTask` that has access to both. It generates `dependency-trace-report.json`.
- The report provides a `"reason": "Uses 3 classes: okhttp3.Call, okhttp3.OkHttpClient, okhttp3.Request"`
- The task has access to data we need, but the generated report is not sufficient

**Options**
- Update `ComputeUsagesTask` to generate a more artifacts
- Update `dependency-trace-report.json` with more information
- Create a separate, similar task to `ComputeUsagesTask`

**Recommendation**
The simplest solution would be for `ComputeUsagesTask` to generate a separate, more detailed report around usages.
- The naming already implies this purpose.
- It has the necessary data dependencies.
- Single-pass to compute both reports would be more efficient.
- Modifying `dependency-trace-report.json` would potentially affect downstream tasks. I'm not sure combining different purposes into a single report is the right approach.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.