openrewrite/rewrite-gradle-plugin

Parsing of Gradle build files doesn't consider submodules

Closed this issue · 5 comments

What version of OpenRewrite are you using?

I am using

  • OpenRewrite latest.release at the time of issue creation
  • Gradle plugin latest.release at the time of issue creation

How are you running OpenRewrite?

I'm using the Gradle Plugin in a multi-module build.

What is the smallest, simplest way to reproduce the problem?

Create a multi-module Gradle build with root, submodule A and submodule B. All projects (root and submodules) apply plugin X. The goal is to remove plugin X by using the "org.openrewrite.gradle.plugins.RemoveBuildPlugin" recipe.

What did you expect to see?

Plugin X should get removed from all projects including root and submodules.

What did you see instead?

Plugin X has only been removed from the root build.gradle file.

Analysis so far

After debugging the current source code i found out that the method org.openrewrite.gradle.isolated.DefaultProjectParser#parseGradleFiles is actually called for all subprojects but doesn't take them into account. Instead the implementation only considers the root project.

Thanks for helping dive in and debug @anuebel ; could you elaborate a bit on what you mean with "only considers the root project"? Which lines are you referring to there, and what change would you make to fix this?

Only considering the root project in this case means, that only the build.gradle (and - if available - settings.gradle) of the root project are subject to recipe application. Gradle-targeting recipes like org.openrewrite.gradle.plugins.ChangePlugin will not be applied to build.gradle files of subprojects.

In order for that to work i'd pass subproject to parseGradleFiles in L831 and change most of the references to the project in parseGradleFiles to the newly passed subproject. I would file a simple - but untested - PR but get a 403 when doing so. The attached patch file should illustrate the change.
feat__include_Gradle_build_files_of_subprojects.patch.txt

Thanks for sharing those details! Regarding that 403: I didn't yet see a fork of rewrite-gradle-plugin under your list of repositories at https://github.com/anuebel?tab=repositories. Perhaps pushing your changes to a fork helps you start a pull request here?

That said I don't know if I'm the best judge of your proposed change; perhaps @shanman190 can weigh in here on your proposal, and how that might affect recipe runs?

Thanks for the tag @timtebeek!

Yes, the included patch is what I imagined would be the fix for the Gradle plugin given it's current state.

@anuebel, as Tim suggested and assuming you are able to do so, creating a fork of the openrewrite-gradle-plugin which under normal circumstances will create a linked copy of the repository in your GitHub user account would be your next step. You can then clone the repository from your user account's link, apply your patch file, push, and then finally submit a pull request containing these changes.

If you are unable to do this, that's fine and we can perform the necessary changes as well to fix this bug.

I've submitted #250. Thanks for the help @shanman190 and @timtebeek.