-
Notifications
You must be signed in to change notification settings - Fork 434
Add DependencyManagement handling #5623
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?
Conversation
…al recipes using a Trait Fix #5304
...e-gradle/src/test/java/org/openrewrite/gradle/trait/GradleDependencyManagementEntryTest.java
Outdated
Show resolved
Hide resolved
…leDependencyManagementEntryTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
When I think about the logistics of it, it feels like What if we introduced a |
|
Here's my analysis of rewrite-maven as a parallel:
So it would make sense I suppose to follow the established pattern. Honestly, I didn't realize that the I think having the trait is fine, but I think the design that I think would work best is a |
…e, restoring the original recipe
// Individual dependencies tend to appear in several places within a given dependency graph. | ||
// Minimize the number of allocations by caching the updated dependencies. | ||
transient Map<org.openrewrite.maven.tree.Dependency, org.openrewrite.maven.tree.Dependency> updatedRequested = new HashMap<>(); | ||
transient Map<org.openrewrite.maven.tree.ResolvedDependency, org.openrewrite.maven.tree.ResolvedDependency> updatedResolved = new HashMap<>(); | ||
transient MavenMetadataFailures mavenMetadataFailures = new MavenMetadataFailures(this); | ||
|
||
@JsonCreator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to find a way to have this here without it failing but without @JsonCreator
as @jkschneider mentioned using @JsonCreator
is to be avoided. I looked at the other maven counterpart, but there it is done using the annotation.
rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeDependency.java
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeManagedDependency.java
Outdated
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/ChangeManagedDependency.java
Outdated
Show resolved
Hide resolved
if (group != null) { | ||
dependency = new GroupArtifactVersion(group, entry, version); | ||
} | ||
} else if (argument instanceof J.MethodInvocation && "mapOf".equals(((J.MethodInvocation) argument).getSimpleName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callout: Not a part of this PR, but this may be an improvement that we can make for the GradleDependency
trait as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Leaving this open for now so that we can create a new issue from this comment later on
rewrite-gradle/src/main/java/org/openrewrite/gradle/trait/GradleDependencyManagementEntry.java
Outdated
Show resolved
Hide resolved
public static SpringDependencyManagementPluginEntry.Matcher springDependencyManagementPluginEntry() { | ||
return new SpringDependencyManagementPluginEntry.Matcher(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @timtebeek confirmed for me, we're no longer going to use the factory pattern going forward, so we can drop this method.
What's changed?
By using a Trait we can both match dependencyManagement sections from recipe perspectives. I also wrote a method that updates the Trait's cursor with an updated dependencyManagement. We can have several more overload methods that call this one with null. Passing null for
group
,artifact
orversion
makes these fields untouched.What's your motivation?
It has been introduced also in the ChangeDependency recipe as an optional boolean (which defaults to true) as that is also how it is done in maven recipe/equivalents
Anything in particular you'd like reviewers to focus on?
I tried to minimize code duplications as it was really becoming a lot of copy pasting / error prone to changes.
I stopped at a point where I feel if we further try to remove duplications, we end up in a hard to follow code flow.
Anyone you would like to review specifically?
@shanman190 or @sambsnyd would be great for an early/conceptual review. Please do not focus on code duplications etc yet. I want to fail fast before spending time in optimizing.
Have you considered any alternatives or workarounds?
As suggested by @shanman190, I went for a postVisit recipe that is optionally adding the dependencyManagement to be aligned with maven equivalents.
ATM, the Trait does not allow for templated strings yet as we would need scanning phases for that so want to come up with support for no-templates strings first and then add templated strings in a separate PR later if required.
Checklist