dependency-analysis-gradle-plugin
dependency-analysis-gradle-plugin copied to clipboard
Add support for Typesafe Project Accessors
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)
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)
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.
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.
Is there anything that still needs to be done here?
At least it needs to be rebased and the conflicts fixed.
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?
@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.