-
I have a scenario where I want to run a recipe that'll upgrade to Spring 4 when a particular library is present in a Maven project. Otherwise, I want a different recipe to run that'll upgrade to Spring 5. Is there a way to automate that decision via recipe configs in my rewrite.yml? For example, if "onlyIfUsing" supported version number matching on the major version that might enable me to make the correct recipe run based on whether the problematic library is present. I see that org.openrewrite.maven.search.DoesNotIncludeDependency exists but cannot find any discussion or end-user usage examples. Not sure if this is what it is for or not... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi! We added Preconditions in Rewrite 8 to allow you to express conditions that should match before your recipe runs. In your case you can likely develop two custom recipes:
Then, for each of those recipes, you can either chain visitors, or link recipes together to run the additional existing recipes that you want to invoke. That way you have relatively straightforward individual recipes that each match in specific conditions, and only then make their changes, instead of a single recipe that always matches and attempts changes, with more complicated decision logic that's harder to test and reason about. Hope that helps! |
Beta Was this translation helpful? Give feedback.
Hi! We added Preconditions in Rewrite 8 to allow you to express conditions that should match before your recipe runs. In your case you can likely develop two custom recipes:
Then, for each of those recipes, you can either chain visitors, or link recipes together to run the additional existing recipes that you want to invoke.
That way you have relatively straightforward individual recipes that each match in specific conditions, and only then make their changes, instead of a single recipe that always matches and attempts changes, with more complicated decisio…