openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
60 stars 37 forks source link

Support or troubleshoot type attribution for types in dependencies added through Gradle company convention plugins #269

Closed timtebeek closed 7 months ago

timtebeek commented 8 months ago

So couple hypotheticals: say you have some company wide Gradle convention plugins, that among other things, add Lombok to project dependencies from a conventions/src/main/groovy/io.moo.java-base.gradle

dependencies {
    // these configurations do not extend from implementation so cannot use its platform
    compileOnly("org.projectlombok:lombok:latest.release")
    annotationProcessor("org.projectlombok:lombok:latest.release")
...

And you then use this plugin with some indirections via a library plugin, to a java-17 plugin, to that base.gradle plugin in a library, and run the rewrite-gradle-plugin against that library.

What you would expect is for the lombok classes to still be available to the Gradle parser for type attribution, and for those types to make it onto LST elements for recipes to discover and use.

Yet what you might find is that FindMissingTypes flags all Lombok annotations themselves as missing types, not the boilerplate they generate. This then trips up LombokValToFinalVar and ends up removing "unused" imports. image (all hypothetical)

We should support such use cases by making sure that any dependencies added through plugins are also added to the parser classpath, or if they already are, troubleshoot why there's missing types on such uses.

shanman190 commented 8 months ago

So the OpenRewrite repositories are a great use case for this as the rewrite-build-gradle-plugin does just this.

If the dependency is on the compileOnly configurarion, I'd expect for that to propagate into the compileClasspath configuration which is handed to the *Parser instances responsible for performing the parsing into the LST elements.

timtebeek commented 7 months ago
timtebeek commented 7 months ago

Looks to be fixed now! šŸŽ‰