Skip to content

Generate OpenRewrite recipes with JavaParser.Builder#classpathFromResources#1918

Merged
rickie merged 8 commits intoPicnicSupermarket:masterfrom
timtebeek:use-classpathFromResources
Oct 27, 2025
Merged

Generate OpenRewrite recipes with JavaParser.Builder#classpathFromResources#1918
rickie merged 8 commits intoPicnicSupermarket:masterfrom
timtebeek:use-classpathFromResources

Conversation

@timtebeek
Copy link
Copy Markdown
Contributor

Add a annotation processor argument to switch to classpath from resource for the generated OpenRewrite recipes:
https://github.com/openrewrite/rewrite-templating/?tab=readme-ov-file#use-javaparserbuilder-classpathfromresourcesctx-guava-31

By default, the annotation processor will use JavaParser.runtimeClasspath() to resolve the classpath for newly generated Java code snippets. If you want to use TypeTables from src/main/resources/META-INF/rewrite/classpath.tsv.gz instead, pass in: -Arewrite.javaParserClasspathFrom=resources.

Right now we're having to replicate the provided dependencies in EPS in rewrite-third-party to get the recipes to work at all, and even then they do not work well in all environments. By switching to type tables we only need to capture the public APIs of the dependencies, for a much smaller and safer runtime.

Follows

@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@timtebeek
Copy link
Copy Markdown
Contributor Author

[WARNING] The following options were not recognized by any processor: '[rewrite.javaParserClasspathFrom]'

Which is odd, since I'm explicitly setting that as supported option here: 🤔
https://github.com/openrewrite/rewrite-templating/blob/a869184ed27513bebec66d4b9e9d9adb7899425b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java#L48-L56

@Stephan202 Stephan202 force-pushed the use-classpathFromResources branch from eeeb4f3 to aa9693d Compare October 13, 2025 12:39
@Stephan202
Copy link
Copy Markdown
Member

The issue manifested only with JDK 25. I rebased and added a commit to move the config to the proper location. But now there's another error you may want to look at. (I just did this in between meetings; can circle back later.)

@timtebeek
Copy link
Copy Markdown
Contributor Author

Thanks yes can confirm; I think it's because over here we use a lib for the annotations, whereas in our tests we had those inlined. Ought to be fixed with a small adjustment to the template processor and a new release.

@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 added this to the 0.26.0 milestone Oct 13, 2025
Copy link
Copy Markdown
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I added one commit. I checked the generated code; LGTM.

Suggested commit message:

Generate OpenRewrite recipes with `JavaParser.Builder#classpathFromResources` (#1918)

@Stephan202 Stephan202 changed the title Use classpathFromResources for OpenRewrite recipes Generate OpenRewrite recipes with JavaParser.Builder#classpathFromResources Oct 13, 2025
@Stephan202 Stephan202 changed the title Generate OpenRewrite recipes with JavaParser.Builder#classpathFromResources Generate OpenRewrite recipes with JavaParser.Builder#classpathFromResources Oct 13, 2025
@Stephan202 Stephan202 requested a review from rickie October 13, 2025 16:33
@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@timtebeek
Copy link
Copy Markdown
Contributor Author

Any concerns here @rickie ? Would love to get this in to make the corresponding changes on our end.

<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>3.16.0</version>
<version>3.17.0</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickie let's merge #1932 first. ❗

@rickie rickie force-pushed the use-classpathFromResources branch from 89624d4 to 6a68d73 Compare October 27, 2025 07:38
@github-actions
Copy link
Copy Markdown

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit 2929920 into PicnicSupermarket:master Oct 27, 2025
17 checks passed
@timtebeek timtebeek deleted the use-classpathFromResources branch October 27, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants