dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
Variant dependency on module suggested to change to implementation
Plugin version 2.4.2
Gradle version 8.11
JDK version 22
(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version 2.0.21
(Optional) Android Gradle Plugin (AGP) version 8.7.2
(Optional) reason output for bugs relating to incorrect advice
Describe the bug I have an environment flavor that has two values; dev, and prod.
One of my modules has code in the main, dev, and prod source sets. It also has a devImplementation(projects.devProperties) dependency:
main
environmentProperties()
dev
internal fun environmentProperties() {
DevProperties.init()
}
prod
internal fun environmentProperties() {}
When I run buildHealth I get the following advice:
Existing dependencies which should be modified to be as indicated:
implementation(projects.devProperties) (was devImplementation)
Running reason --id :devProperties prints:
Source: devDebug, main
----------------------
* Uses 1 class: com.me.DevProperties (implies implementation).
Source: devRelease, main
------------------------
* Uses 1 class: com.me.DevProperties (implies implementation).
Expected behavior
I would expect that since DevProperties is only referenced in the dev source set, that the dependency should be on devImplementation instead of implementation.
Maybe the root cause is this AGP issue I just noticed - https://issuetracker.google.com/issues/379441921
Also I was disabling all of the prod variants for local builds. When I stopped doing that, buildHealth now says I should be using devDebugImplementation instead of devImplementation.
Thanks for the report! Do you have a minimal reproducer?
Possibly 😬
I haven't tested it yet due to lack of time, but I'll post it here when I get to it.
./gradlew buildHealth currently works in that project.
Changing implementation(projects.destinations.devSettings) to devImplementation in nav/build.gradle.kts causes buildHealth to advise changing from devImplementation to implementation, but as far as I can tell, none of its API is accessed outside of the dev source set.
Still not sure if this is related or not, but if you comment out dependency.analysis.android.ignore.variants in gradle.properties and run CI=true ./gradlew buildHealth (the CI=true enables the prod variant) there are a lot more errors.
Thanks for the repro! I'll have to take a look to be sure, but in general when you configure the plugin to ignore/exclude various things, the final report can be incorrect for some meaning of that word. The report will have the greatest level of accuracy ("perfect" minus some possible bugs) when the analysis is global.