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

Used constant of dependency not recognized #408

Closed
gabrielittner opened this issue Jun 3, 2021 · 4 comments
Closed

Used constant of dependency not recognized #408

gabrielittner opened this issue Jun 3, 2021 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@gabrielittner
Copy link
Contributor

Build scan link

Reproducer instead constants.zip

Plugin version

0.73.1-SNAPSHOT

Gradle version

7.0.0

Android Gradle Plugin (AGP) version

n/a

Describe the bug

The root project declares a constant like this

const val ARG_WINDOW_DRAW_BELOW_NAV_BAR = "core.window.drawBelowNavigationBar"

Another project uses that constant, for example

fun foo() {
    println(ARG_WINDOW_DRAW_BELOW_STATUS_BAR)
}

The advice is to remove the dependency on the project declaring the constant, which would then make compilation fail

Advice for project :settings
Unused dependencies which should be removed:
- implementation(project(":"))

To Reproduce
Steps to reproduce the behavior:

  1. Run buildHealth in the sample project

Expected behavior

There shouldn't be advice to remove the dependency

Additional context

In my project from work where I initially found this it only started happening after updating from Kotlin 1.4.32 to 1.5.10. In the reproducer it seems to happen regardless of Kotlin version

@autonomousapps
Copy link
Owner

The kotlin compiler doesn't use the constant pool (unlike javac), so to detect constant usage, the plugin looks at import statements in the source code and tries to infer which dependency is associated with that import statement. This works, but not if you have a fully-qualified usage (i.e., no import statement).

Thanks for the reproducer, I'll take a look.

@gabrielittner
Copy link
Contributor Author

The reproducer does not have an import because I just used the same package when creating it. When I move the usage to a different package and add the import I'm seeing what I see in our work project:

Kotlin 1.4.32

> Task :buildHealth
Advice for root project
Looking good! No changes needed

Advice for project :settings
Looking good! No changes needed

Kotlin 1.5.10

> Task :buildHealth
Advice for root project
Looking good! No changes needed

Advice for project :settings
Unused dependencies which should be removed:
- implementation(project(":"))

constants2.zip

@autonomousapps
Copy link
Owner

autonomousapps commented Jun 4, 2021 via email

@autonomousapps
Copy link
Owner

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants