Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of Gradle build files doesn't consider submodules #245

Closed
anuebel opened this issue Nov 22, 2023 · 5 comments · Fixed by #250
Closed

Parsing of Gradle build files doesn't consider submodules #245

anuebel opened this issue Nov 22, 2023 · 5 comments · Fixed by #250
Labels
bug Something isn't working parser-gradle

Comments

@anuebel
Copy link
Contributor

anuebel commented Nov 22, 2023

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.

@anuebel anuebel added the bug Something isn't working label Nov 22, 2023
@timtebeek timtebeek moved this to Backlog in OpenRewrite Nov 30, 2023
@timtebeek
Copy link
Contributor

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?

@anuebel
Copy link
Contributor Author

anuebel commented Dec 11, 2023

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

@timtebeek
Copy link
Contributor

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?

@shanman190
Copy link
Collaborator

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.

@anuebel
Copy link
Contributor Author

anuebel commented Dec 12, 2023

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

@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-gradle
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants