openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
1.98k stars 293 forks source link

"Add Maven Parent" recipe #4239

Open rcsilva83 opened 1 month ago

rcsilva83 commented 1 month ago

What problem are you trying to solve?

I need to add a parent POM to my projects.

Describe the solution you'd like

I'd like a recipe for that as there already has one for changing the Maven parent.

Have you considered any alternatives or workarounds?

Using text recipe

Additional context

Are you interested in contributing this feature to OpenRewrite?

I can try :)

timtebeek commented 1 month ago

hi @rcsilva83 ! Thanks for the suggestion. For this one I'd assume the implementation would be rather similar to Change Maven Parent https://github.com/openrewrite/rewrite/blob/28e7b125655fa507d68f80ed1dafa2dee38a38fa/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java#L44

Perhaps we can start with a draft PR with some unit tests, and then I'll help guide you through what's needed beyond that.

Tests are also a great way to think through and codify how you'd want to handle certain cases, like:

rcsilva83 commented 1 month ago

Hi @timtebeek

I'm trying to build the project on my machine but I'm having issues:

A problem occurred configuring project ':tools:language-parser-builder'.
> Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any, implementation=vendor-specific} for WINDOWS on x86_64.
   > No locally installed toolchains match and toolchain download repositories have not been configured.

I'm running with JDK21 but it I run with JDK17 I have the same problem with languageVersion=21. I'm trying to configure org.gradle.java.installations.paths on gradle.properties but nothing changed...

Can you help me with this?

timtebeek commented 1 month ago

hi! That's curious; are you using any non standard paths for your installed JDKs? I know Gradle does some discovery that might fail to detect your JDK paths.

You might be able to work around this though by following these instructions to not load troublesome modules: https://github.com/openrewrite/rewrite/blob/28e7b125655fa507d68f80ed1dafa2dee38a38fa/IDE.properties.tmp#L1-L7

We also have some more general IDE setup instructions on these pages.

Hope that helps!