Skip to content

Gradle - Add tests for update in dependencyManagement #5304

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ThomasVitale
Copy link

@ThomasVitale ThomasVitale commented Apr 15, 2025

What's changed?

  • Introduced tests for demonstrating the issue.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

  • How to implement the new use case?

Anyone you would like to review specifically?

@timtebeek

Have you considered any alternatives or workarounds?

Yes, workaround considered and explained in #5300, but not feasible in certain scenarios.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files


@Issue("https://github.com/openrewrite/rewrite/issues/5300")
@Test
@Ignore
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignored since this is currently failing:

Recipe was expected to make a change but made no changes.
java.lang.AssertionError: Recipe was expected to make a change but made no changes.
	at org.openrewrite.test.LargeSourceSetCheckingExpectedCycles.afterCycle(LargeSourceSetCheckingExpectedCycles.java:119)
	at org.openrewrite.RecipeScheduler.runRecipeCycles(RecipeScheduler.java:98)
	at org.openrewrite.RecipeScheduler.scheduleRun(RecipeScheduler.java:41)
	at org.openrewrite.Recipe.run(Recipe.java:438)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:377)
	at org.openrewrite.test.RewriteTest.rewriteRun(RewriteTest.java:130)
	at org.openrewrite.gradle.UpgradeDependencyVersionTest.makeChangesInDependencyManagement(UpgradeDependencyVersionTest.java:436)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also probably duplicate this test with a Gradle Kotlin DSL variation as well.

@timtebeek
Copy link
Member

Thanks for the start here @ThomasVitale ! I'm going to ask if @shanman190 has some guiding hints here for whether we want to make these changes as part of this recipe, and if that should be in a separate visitor perhaps. He's our friendly community authority on all things Gradle. 🧙🏻‍♂️

@ThomasVitale
Copy link
Author

Perfect, thank you so much!

Copy link
Contributor

@shanman190 shanman190 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably best as Tim suggested to do this as a separate dedicated visitor given that this section is 1) not type attributed and 2) extremely specific to the Spring Dependency Management plugin.

As you'll see with the other visitors, I would suggest utilizing the JavaIsoVisitor, then also performing similar updates to handle both Gradle Groovy DSL and Gradle Kotlin DSL both.

If you choose to also handle variable updates -- which it seems likely given the test case you've written here -- then you may end up having to collect the parameter names within the scanning phase of the existing JavaIsoVisitor. It's also possible to use a separate visitor for this phase as well though, if you feel that it comes out more cleanly.

Some additional notes:

@@ -394,6 +395,99 @@ implementation platform("com.google.guava:guava:30.1.1-jre")
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/5300")
@Test
void doesNotMakeChangesInDependencyManagement() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test feels a bit extraneous to me since it's effectively never going to do anything from a recipe standpoint.


@Issue("https://github.com/openrewrite/rewrite/issues/5300")
@Test
@Ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also probably duplicate this test with a Gradle Kotlin DSL variation as well.

@ThomasVitale
Copy link
Author

@shanman190 thanks so much for the inputs. I'll look a bit deeper into the JavaIsoVisitor and consider support for both the Groovy DSL and Kotlin DSL. I hope I'll get a draft PR ready soon.

@timtebeek timtebeek marked this pull request as draft April 24, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants