-
Notifications
You must be signed in to change notification settings - Fork 424
Add AddPlatformDependency recipe. #5371
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
base: main
Are you sure you want to change the base?
Add AddPlatformDependency recipe. #5371
Conversation
Currently decided to not include "onlyIfUsing" in this recipe, mostly as unsure if it should be explicit if it would be best for users to be explicit in where they want to add a platform dependency? Would appreciate any thoughts, @timtebeek / @shanman190! |
So having only read your comment here about Maybe if we go ahead and include something like a |
rewrite-gradle/src/main/java/org/openrewrite/gradle/AddPlatformDependency.java
Outdated
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/AddPlatformDependency.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Shannon Pamperl <[email protected]>
Maybe there's the option of using the dependencies also to work out whether to add a platform dependency? E.g. if a module is using any dependencies matching a group Sorry, could you help me understand more on your second point, not sure I followed. Would that be for refactoring out the |
The short answer is that preconditions are a much more powerful and expressive way to capture these types of extra conditioning (types in use, acceptable file patterns, etc). With preconditions we can build all kinds of acceptance rules and combine them together arbitrarily in declarative recipes, including using DependencyInsight in the manner that you described for other Spring Boot dependencies being present. There are a ton of possible reasons that you may want to use a condition around when to add a dependency and by having the flexibility of preconditions it means that each of those different "reasons" can be utilized arbitrarily as a recipe author is building out their recipe(s). |
Thanks for elaborating! Is the suggestion then that these recipes don't require such restrictions built in and we can assume them to be handled in the precondition recipes, and embedding logic into the recipe to restrict to specific modules isn't required? |
That's kinda what I was thinking. I'd probably go one step further to go ahead and create the precondition recipe (not 100% on the name of it though) while we're here thinking about it, but that's not strictly required. WDYT, @timtebeek ? |
Do you mean to create a recipe to check if a GradleProject is using any dependency managed by a BOM? And then to add that as a precondition check on the AddPlatformDependency recipe? would be ideal, I think, to make something like this just work out of the box: @Test
void twoProjects() {
rewriteRun(
spec -> spec.recipe(new AddPlatformDependency(
"org.springframework.boot", "spring-boot-dependencies", "3.2.4", null, null, null)),
mavenProject("projectA",
buildGradle(
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation "org.springframework:spring-core:6.1.5"
}
""",
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation platform("org.springframework.boot:spring-boot-dependencies:3.2.4")
testImplementation "org.springframework:spring-core"
}
"""
)
),
mavenProject("projectB",
buildGradle(
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
"""
// No change, as we're not using any dependencies managed in the platform bom added
)
)
);
} |
So I was more thinking of:
I do like the idea of scheduling a |
rewrite-gradle/src/main/java/org/openrewrite/gradle/GradleConfigurationFilter.java
Outdated
Show resolved
Hide resolved
…igurationFilter.java Co-authored-by: Tim te Beek <[email protected]>
Just a FYI, I have an idea that I'd like to play with locally for a day or two that would change the need for the |
Added more test cases and made the changes mentioned. Marked PR as ready but of course pending any changes you wish to make regarding the configuration names as already mentioned 😄 One thing I'm not sure about is how useful the "inferred" configuration would be, rather than using an explicit configuration from the recipe parameters. Let me know if it should be mandatory to specify the configuration for platform dependencies instead of having such logic as well! |
Just did a review on your code, nice contribution @BrendanHart! I like the introduction of the GradleConfigurationFilter class. I was wondering though, does it make sense to introduce an abstract class above the AddPlatformDependency and AddDependency recipes? There is a lot of duplicated code there going on in the visitor part. Another option would be to create a separate Dependency visitor class with an "isPlatform" flag or something. What do you think? Also notice Tim's comment in the original issue:
|
I've still got this @jevanlingen . I've got a |
Thanks for the review @jevanlingen ! Will await @shanman190 's changes and any further comments I can address. |
What's changed?
Add recipe to support adding platform/enforcedPlatform dependencies to Gradle build files.
What's your motivation?
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
Checklist