autonomousapps / autonomousapps/dependency-analysis-gradle-plugin
kapt is reported as unused plugin on an excluded unused annotation processor dependency
- 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.**
The plugin is raising an error that the `kapt` plugin is unused even when it's applied to an [_excluded_](https://github.com/ivanalvarado/Dependency-Analysis-Plugin-Repro/blob/main/build-configuration/project-health.gradle#L14) unused dependency in a gradle project.
For example, in [this project](https://github.com/ivanalvarado/Dependency-Analysis-Plugin-Repro) our dependency analysis plugin is configured to not fail if `'com.google.dagger:hilt-android-compiler'` is unused for annotation processors:
[`build-configuration/project-health.gradle`](https://github.com/ivanalvarado/Dependency-Analysis-Plugin-Repro/blob/main/build-configuration/project-health.gradle)
```groovy
dependencyAnalysis {
issues {
onUnusedDependencies {
severity('ignore')
}
onUsedTransitiveDependencies {
severity('ignore')
}
onIncorrectConfiguration {
severity('ignore')
}
onUnusedAnnotationProcessors {
severity('fail')
exclude('com.google.dagger:hilt-android-compiler')
}
onRedundantPlugins {
severity('fail')
}
ignoreKtx(true)
}
}
```
In the [`mylibrary/build.gradle`](https://github.com/ivanalvarado/Dependency-Analysis-Plugin-Repro/blob/main/mylibrary/build.gradle) we have `'com.google.dagger:hilt-android-compiler:2.43.2'` configured with `kapt`:
```groovy
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "kotlin-kapt"
...
dependencies {
kapt 'com.google.dagger:hilt-android-compiler:2.43.2'
...
implementation 'com.google.dagger:hilt-android:2.43.2'
}
```
When we run dependency analysis plugin by doing `./gradlew :mylibrary:projectHealth`, the plugin correctly excludes `'com.google.dagger:hilt-android-compiler'` from being reported as an unused annotation processor, but raises that the `kapt` plugin was applied but no annotation processors were used:
```
> Task :mylibrary:projectHealth FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':mylibrary:projectHealth'.
> Unused plugins that can be removed:
kotlin-kapt: this project has the kotlin-kapt (org.jetbrains.kotlin.kapt) plugin applied, but there are no used annotation processors.
```
### **Describe the solution you'd like**
We expect the plugin to detect that `'com.google.dagger:hilt-android-compiler'` is excluded and because it's using the `kapt` plugin, **the plugin shouldn't be reported as unused**.
### **Describe alternatives you've considered**
We are able to add a workaround for now by excluding `kotlin-kapt` as a redundant plugin in the dependency analysis configuration. However, we feel this is a bit aggressive:
```groovy
onRedundantPlugins {
severity('fail')
exclude('kotlin-kapt')
}
```
### **Additional context**
We assume that the plugin is detecting that because `'com.google.dagger:hilt-android-compiler'` is unused and configured with `kapt`, then it effectively detects the `kapt` plugin as unused as well and thus raises this as an error.
We've create a project that easily reproduces this behavior: https://github.com/ivanalvarado/Dependency-Analysis-Plugin-Repro
Simply run `./gradlew :mylibrary:projectHealth` and observe the failure.
Contributor guide
Research direction
Reproduce the failure with ./gradlew :mylibrary:projectHealth in the linked Dependency-Analysis-Plugin-Repro project, then inspect build-configuration/project-health.gradle and mylibrary/build.gradle. Trace how the excluded hilt-android-compiler dependency affects the redundant kotlin-kapt plugin report. Done means the dependency remains excluded without reporting kotlin-kapt as unused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100