openrewrite / rewrite

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

Test OpenRewrite against early access builds of Java 21 #3170

Closed timtebeek closed 10 months ago

timtebeek commented 1 year ago

Capturing a comment on an early naive attempt in a separate issue in the lead up to Java 21 in September.

this is a bit more complicated than just switching the GitHub Actions Java versions due to us using Java toolchains. https://github.com/openrewrite/rewrite-build-gradle-plugin/blob/47369d2da1d62bc0a63a7f0a680129eb168aece4/src/main/java/org/openrewrite/gradle/RewriteJavaPlugin.java#L52 So basically with this current setup, all that's being tested is that Gradle can run as 20-ea/21-ea. In order to actually test rewrite against the newer version, we would have to instead switch the toolchains in use.

It might be helpful to already start testing against early access builds of Java 21. We have a workflow we can trigger manually that runs on Java 21, but does not yet update the toolchain version: https://github.com/openrewrite/rewrite/actions/workflows/ci-early-access.yml It also currently fails as it seems there's not yet a 21-ea available in GitHub Actions, despite using the recommended syntax for setup-java.

If we run into any issues, it would be good to report those to: https://wiki.openjdk.org/display/quality/Quality+Outreach

hazendaz commented 1 year ago

21-ea is available in GHA. Has been for a long time. The problem is open rewrite fails on reading it. Gets error run Failed: For input string: "21-ea"

Would be great if rewrite could handle "ea" versions.

hazendaz commented 1 year ago

Example project -> https://github.com/mybatis/parent/actions/runs/4945151148. Example yml -> https://github.com/mybatis/parent/blob/master/.github/workflows/ci.yaml

Error produced

Error: Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run (default) on project mybatis-parent: Execution default of goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run failed: For input string: "21-ea" -> [Help 1]

timtebeek commented 1 year ago

Thanks for chiming in here @hazendaz ; Had no idea you have the rewrite-plugin in your parent project, but that's certainly something we want to support. I created a fork to get a stacktrace:

 Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run (default) on project mybatis-parent: Execution default of goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run failed: For input string: "21-ea" -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run (default) on project mybatis-parent: Execution default of goal org.openrewrite.maven:rewrite-maven-plugin:4.45.0:run failed: For input string: "21-ea"
Caused by: java.lang.NumberFormatException: For input string: "21-ea"
    at java.lang.NumberFormatException.forInputString (NumberFormatException.java:67)
    at java.lang.Integer.parseInt (Integer.java:661)
    at java.lang.Integer.parseInt (Integer.java:777)
    at org.openrewrite.java.JavaParser.fromJavaVersion (JavaParser.java:210)
    at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:137)

Looks like an easy fix: https://github.com/openrewrite/rewrite/pull/3242

hazendaz commented 1 year ago

@timtebeek Thanks! Our initial intent with mybatis is to prevent star imports which impsort-maven-plugin and spotless-maven-plugin should support. Impsort-maven-plugin outright declined doing so and spotless-maven-plugin is considering it but not seeing value. Given rewrite does out of the box with the remove unused imports rule works for me in that case. So this was newly introduced and we run all our builds on the supported jdks and future ones. I was planning to release after adding in rewrite but ran into that issue. I was going to simply raise ticket then ran across this and probably add a profile to work around the concern but having a fix would be great. That at least makes my setup easier :)

Less related, over time I plan to add rewrite into the mix at a much higher capacity as it has proven since my first experiences in late 2021 to have significantly improved and the support / release cycles are fast so improvements keep pace more-so than a lot of other tools that try to do the same type of stuff. Very much love this project overall. In my day job capacity, we have a bot setup that runs rewrite for a number of the well proved out rewrites and in my capacity there I'm trying to evaluate how good of a state we are for java 21 well ahead of the September release so we can quickly jump at that time. So this one seems like easy one especially per your PR 👍

timtebeek commented 1 year ago

Hi @hazendaz; Thanks for the background and glad to hear you like the project! I've merged my PR, so you should be able to try out this change through our snapshot versions. If needed I can probably do a patch release tomorrow or the day after; I'm hoping to get in another few minor fixes first.

To make it even easier for you to apply changes in bulk, I've also gone ahead and added the mybatis projects to our platform. When you create a new repository group containing the mybatis projects, you can run recipes against those in seconds. Should be much quicker than the changes I've seen you made in the latest release.

Here's a temporary link showing a couple quick fixes applied broadly: https://public.moderne.io/results/NjzLZ We specifically offer these tools for free on OSS projects. :) Feel free to explore that and let me know what you think!

If desired we can also have a look at best practice or migration recipes for users of MyBatis; best to chime in on our Slack if that's of interest.

hazendaz commented 1 year ago

Thank you for the info. Will check this out this weekend.

timtebeek commented 10 months ago

We now support migrating to Java 21 and build on Java 21 by default for OpenRewrite:

We're not yet running our tests with Java 21 by default, due to some issues with the Gradle toolchain, partially documented here:

I think we can close this issue; do reach out if there's anything above that you'd like to follow up on separately!