autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.66k stars 116 forks source link

Add support for Typesafe Project Accessors #1189

Open ivanalvarado opened 1 month ago

ivanalvarado commented 1 month ago

Description

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)
alllex commented 6 days ago

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 commented 6 days ago

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.

autonomousapps commented 6 days ago

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.