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

Add support for Typesafe Project Accessors

Open ivanalvarado opened this issue 1 year ago • 3 comments
trafficstars

Description

  • Adds support for typesafe project accessors through extension configuration
  • Addresses: https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/844

Usage

dependencyAnalysis {
   projectProperties {
     // (Optional) Specify whether to print advice in typesafe-project-accessors format
     // Example: project(":foo:bar:baz") vs. projects.foo.bar.baz
     useTypesafeProjectAccessors(true)
   }
 }

Example

If this property is set to true, the console report will output:

Existing dependencies which should be modified to be as indicated:	
  implementation projects.account.impl (was api)
  implementation projects.account.public (was api)	

instead of

Existing dependencies which should be modified to be as indicated:	
  implementation project(':account:impl') (was api)	
  implementation project(':account:public') (was api)

ivanalvarado avatar May 18 '24 00:05 ivanalvarado

Ideally, the error should provide the suggestion compatible with the corresponding build script DSL, i.e. Groovy vs Kotlin.

For Kotlin DSL it should be:

Existing dependencies which should be modified to be as indicated:	
  implementation(projects.account.impl) (was api)
  implementation(projects.account.public) (was api)	

alllex avatar Jun 25 '24 10:06 alllex

Given that it's not possible to detect whether type-safe accessors are enabled and that it might not be easy to detect the correct DSL, I suggest adding those as formatting options in the plugin configuration.

This will already be immediately useful for projects using the plugin because the errors will provide a better UX.

On that note, even if the type-safe accessors become stable and are ON by default, the users might still prefer the stringy project coordinates. This means they would still prefer to see the errors displayed in the format matching theirs. Thus, the plugin would still require configurability in this aspect.

alllex avatar Jun 25 '24 10:06 alllex

Given that it's not possible to detect whether type-safe accessors are enabled and that it might not be easy to detect the correct DSL, I suggest adding those as formatting options in the plugin configuration.

The plugin currently does detect whether the project is using Groovy or Kotlin based on the file extension (.gradle or .gradle.kts), and formats the output accordingly. All the tests here use Groovy DSL for historical reasons.

autonomousapps avatar Jun 25 '24 17:06 autonomousapps

Is there anything that still needs to be done here?

eygraber avatar Nov 26 '24 21:11 eygraber

At least it needs to be rebased and the conflicts fixed.

autonomousapps avatar Nov 26 '24 22:11 autonomousapps

Here's the error:

> Task :compileTestKotlin FAILED
e: file:///home/runner/work/dependency-analysis-gradle-plugin/dependency-analysis-gradle-plugin/src/test/kotlin/com/autonomousapps/internal/parse/KotlinBuildScriptDependenciesRewriterTest.kt:60:93 No value passed for parameter 'useTypesafeProjectAccessors'

I haven't looked at the latest code yet, but I would be suspicious of something that was suddenly a required parameter. There should be a default value, I think?

autonomousapps avatar Feb 24 '25 18:02 autonomousapps

@ivanalvarado sorry for the delay. I decided to grab your code and push it in a separate PR at https://github.com/autonomousapps/dependency-analysis-gradle-plugin/pull/1414. That is now green and I'll be merging it.

autonomousapps avatar Apr 10 '25 18:04 autonomousapps