Fix AddDependency onlyIfUsing ignored in declarative recipes#6822
Closed
salockhart wants to merge 1 commit intoopenrewrite:mainfrom
Closed
Fix AddDependency onlyIfUsing ignored in declarative recipes#6822salockhart wants to merge 1 commit intoopenrewrite:mainfrom
salockhart wants to merge 1 commit intoopenrewrite:mainfrom
Conversation
When a ScanningRecipe like AddDependency was used inside a declarative YAML recipe, scanNestedScanningRecipes() recursed into getRecipeList() of all recipes — including leaf ScanningRecipes. This caused their accumulators to be populated during precondition scanning rather than during normal recipe execution, breaking onlyIfUsing filtering. Fix: Distinguish DeclarativeRecipe containers (recurse into raw preconditions and recipeList fields) from leaf ScanningRecipes (skip recursion — let the framework handle their scanning during execution). Raw fields are used instead of getRecipeList() to avoid PreconditionBellwether wrapping. Tests: Added addDependencyOnlyIfUsingInDeclarativeRecipe() in both rewrite-maven and rewrite-gradle with two projects — one using Guava (dependency added) and one not (dependency left unchanged). Fixes #6821
9d5aded to
8532fab
Compare
Author
|
I think this may have been solved (better) in #6834 - once there's a release with that in it, I'll verify if it solves my issue and close this if so. |
Member
|
Thanks, that's landed in: c32d382 If you locally install the Maven or gradle plugin you should be able to verify. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6821
What's changed?
When scanning for nested recipes, we now only look at preconditions, not all recipes. scanNestedScanningRecipes() was recursively processing all recipes in getRecipeList() during precondition scanning, causing ScanningRecipes to be invoked twice with different accumulators.
What's your motivation?
Only recursively scan preconditions, not the main recipe list. This ensures each ScanningRecipe uses the same accumulator for both getScanner() and getVisitor() calls.
onlyIfUsingnot working properly inorg.openrewrite.gradle.AddDependency#6821 . It's a shot in the dark, though, so I'm very open to what the correct solution might be!Anything in particular you'd like reviewers to focus on?
The change is fairly small, I just want to make sure it doesn't have any other side effects I'm not aware of.
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
Checklist