-
Notifications
You must be signed in to change notification settings - Fork 364
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
feat: Added functionality to Gradle ChangeDependency to avoid duplica… #4523
Draft
ashakirin
wants to merge
1
commit into
openrewrite:main
Choose a base branch
from
ashakirin:feature/avoid-duplication-change-dependency-gradle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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.
This either needs to be evaluated when we have found the dependency OR precomputed by configurations that contain it as a first order dependency.
With the current implementation, if the new dependency was in
testImplementation
, but the old is inimplementation
, we would incorrectly remove the necessary dependency.The converse side of this, where the new dependency has now been added to a configuration upstream of the current one, I think right now we should leave as out of scope and for a future cleanup duplicate dependencies recipe instead.
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.
@shanman190: I think the current behaviour need to be fixed anyway, because it deliveries very strange result, if new dependency already exists:
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.
@shanman190: do you generally interpret this as consistent case to have dependency in testImplementation and the same dependency with older version in implementation?
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.
Gradle configurations are a foundational component of Gradle. I was merely using
implementation
andtestImplementation
as examples. The more specific issue is when the old dependency is in a configuration upstream from the new dependency. (Ex:api
->implementation
;implementation
->testImplementation
).The present implementation doesn't account for the Gradle configuration that the existing dependency is in or if the new dependency is strictly upstream from itself and as a result, illustrated by my example, shows how the current implementation would become broken and can lead directly to code that no longer compiles in these situations. A recipe that would result in code that fails to compile would violate OpenRewrite's do no harm principle.
Just to be clear, what you're wanting to achieve is possible, the decisioning just needs to happen where I'm indicating and taking into account the current configuration (gotten by looking up the configuration using
MethodInvocation#getSimpleName
), then to be able to remove more often (ie. The new dependency is not in the same configuration as the old) looking at the configurations upstream to see if the new dependency is present.If this still isn't clear enough, I'll add a couple of test cases that I would expect to pass to help illustrate the problem and intended positive and negative cases.