dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Use Generated Project Accessors

Open eygraber opened this issue 2 years ago • 8 comments

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

eygraber avatar Jan 12 '23 17:01 eygraber

Thanks for the issue. Can you elaborate on what you mean by "or printing advice, they don't work so well"?

autonomousapps avatar Jan 20 '23 12:01 autonomousapps

I mean that usages of projects.foo get replaced with project(":foo")

eygraber avatar Jan 20 '23 16:01 eygraber

I wonder if you can use https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/794#issuecomment-1349005040 as a workaround?

autonomousapps avatar Jan 24 '23 15:01 autonomousapps

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.

eygraber avatar Jan 24 '23 15:01 eygraber

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

eygraber avatar Feb 27 '24 21:02 eygraber

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

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 🙈 Zrzut ekranu 2024-03-20 o 08 39 25

dees91 avatar Mar 20 '24 07:03 dees91