Skip to content

Support adding platform dependencies to Gradle project #5357

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

Open
BrendanHart opened this issue Apr 28, 2025 · 7 comments · May be fixed by #5371
Open

Support adding platform dependencies to Gradle project #5357

BrendanHart opened this issue Apr 28, 2025 · 7 comments · May be fixed by #5371
Assignees
Labels
enhancement New feature or request

Comments

@BrendanHart
Copy link
Contributor

BrendanHart commented Apr 28, 2025

What problem are you trying to solve?

It would be useful to be able to add platform dependencies to a project.

Following from this, with RemoveRedundantDependencyVersions

may become possible via a declarative recipe?

Describe the solution you'd like

Improve the AddDependency recipe to support adding platform dependencies

Are you interested in contributing this feature to OpenRewrite?

Yes

@BrendanHart BrendanHart added the enhancement New feature or request label Apr 28, 2025
@timtebeek timtebeek moved this to Backlog in OpenRewrite Apr 28, 2025
@BrendanHart
Copy link
Contributor Author

@timtebeek happy to pick this up also, please assign to me if that's okay!

@timtebeek
Copy link
Member

Sure yes thanks, much appreciated! I'm thinking it might be best as a separate recipe, such that we don't have to update all downstream usage of AddDependency if an option were too be added there.

@BrendanHart
Copy link
Contributor Author

BrendanHart commented Apr 28, 2025

My initial thoughts were that it would be a new optional parameter to the AddDependency recipe, since when platform is added it's essentially just an extra layer between the configuration level (e.g. implementation) and the dependency coordinates as I understand it. Since it's an optional parameter it shouldn't break the existing contract and require other recipes to be updated (please correct me if I'm wrong).

If you feel a separate recipe is still better then happy to do so 😄

Another thought, maybe they can just share the visitor, and create a separate recipe like AddPlatformDependency.

@shanman190
Copy link
Contributor

shanman190 commented Apr 29, 2025

So Maven opted for AddManagedDependency which allows adding a BOM as an import. I'd envision something almost akin to that for Gradle rather than adding an option to AddDependency itself. Almost all of the adding logic is already in the externalized visitor (AddDependencyVisitor which should be fine to add the extra parameters to), so there shouldn't be much that is needed for a top-level recipe. Maybe AddPlatformDependency with an option to choose between platform vs enforcedPlatform?

@timtebeek
Copy link
Member

I think indeed an explicit AddPlatformDependency would be best.

When changing AddDependency we'd have to update any downstream usage explicit usage, like this example here, or would have to add backwards compatible constructors. Neither is very appealing given the long delay we'd see in adoption downstream.

Sharing code with the visitor as described above is of course possible and preferred here. Thanks both!

@BrendanHart
Copy link
Contributor Author

BrendanHart commented Apr 29, 2025

Sure, thanks for the help both! Will take a look at this.

Example was helpful too @timtebeek , I was originally just thinking about use within a declarative recipe style but didn't consider the constructor use like you have shown!

@timtebeek
Copy link
Member

No problem at all, and thanks for getting clarity before jumping into an implementation, as it's a lot easier to steer now as opposed to when a lot have changes have gone in. :) Look forward to the PR!

@BrendanHart BrendanHart linked a pull request May 3, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

3 participants