Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant dependency on module suggested to change to implementation #1312

Open
eygraber opened this issue Nov 18, 2024 · 5 comments
Open

Variant dependency on module suggested to change to implementation #1312

eygraber opened this issue Nov 18, 2024 · 5 comments
Milestone

Comments

@eygraber
Copy link

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.

@eygraber
Copy link
Author

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.

@autonomousapps autonomousapps added bug Something isn't working toolchain:android labels Nov 21, 2024
@autonomousapps
Copy link
Owner

Thanks for the report! Do you have a minimal reproducer?

@eygraber
Copy link
Author

Possibly 😬

I haven't tested it yet due to lack of time, but I'll post it here when I get to it.

@eygraber
Copy link
Author

repro.zip

./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.

@autonomousapps autonomousapps added this to the next milestone Nov 27, 2024
@autonomousapps
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants