dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
Use Generated Project Accessors
Is your feature request related to a problem? Please describe.
Usages of Project accessors (e.g. implementation(projects.foo)) are detected by the plugin, but when it comes to fixing issues with them, or printing advice, they don't work so well.
Describe the solution you'd like
Looking for a match in the project accessors if they are enabled. I've filed an issue with Gradle to support this without violating project isolation.
subprojects.forEach { subproject ->
val projectAccessor = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, subproject.path.replace(':', '.'))
map.put(subproject.path, "projects$projectAccessor")
}
Describe alternatives you've considered
The alternative would be for users to do this in their own projects.
Additional context Similar to #794
Thanks for the issue. Can you elaborate on what you mean by "or printing advice, they don't work so well"?
I mean that usages of projects.foo get replaced with project(":foo")
I wonder if you can use https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/794#issuecomment-1349005040 as a workaround?
I included the workaround I'm using in the OP (although it doesn't work perfectly in all cases). I opened this issue to suggest including it in the plugin.
One issue with the workaround that I posted (which is based on #794) is that the value in map gets wrapped in project().
So if I have a project foo, and access it with projects.foo, the plugin uses project(projects.foo), which doesn't compile because project doesn't take a ProjectDependency (which is the type of projects.foo).
One issue with the workaround that I posted (which is based on #794) is that the value in
mapgets wrapped inproject().So if I have a project
foo, and access it withprojects.foo, the plugin usesproject(projects.foo), which doesn't compile becauseprojectdoesn't take aProjectDependency(which is the type ofprojects.foo).
I have a similar problem, in my multi-module project we use version catalog and declare dependencies as:
implementation(projects.common.a)
implementation(projects.feature.foo)
I came to a similar point and tried to use map:
subprojects.forEach {
map.put(it.path, "projects${it.path.replace(":", ".")}")
}
but I also get suggestions wrapped as
implementation(project(projects.common.a))
implementation(project(projects.feature.foo))
which does not compile
have you maybe found any workaround?
PS
for now my workaround is to kind of post-process result of fixDependencies by using the Replace in Files function with the regex option in Android Studio 🙈