Closed kkom closed 3 years ago
Hi @kkom!
does openwrite necessary need to be applied as a plugin to a Maven or Gradle project?
The simple answer is no. The build tool plugins are one of several different possible workflows to execute recipes on a repository or set of repositories.
There's a team at Moderne working on applying Rewrite recipes in batch across large swaths of code outside of the build: https://youtu.be/s8uR-EmxMUU.
The basic requirement is to have some process to produce the AST (which can be done in batch itself), store them off somewhere in a serialized form, deserialize them and execute the recipe.
On the other hand, jscodeshift works on AST as well
Rewrite's AST operates on a type-attributed AST to be able to make accurate changes. This requires the project's classpath of binary dependencies to produce. Whatever mechanism is used for production of ASTs needs to be aware of the classpath, and build tools are of course designed to produce this.
without having to add openrewrite and, more importantly, the specific recipes to each individual Gradle project.
This is tough with Gradle unless your organization has a central plugin that it distributes to all team. With Maven, we typically see rewrite distributed as part of a parent POM that is shared amongst teams.
Happy to chat more!
Thank you so much for your quick and extensive response @jkschneider ! We're going to give it a try from a Docker container then and report back / ask any questions if some interesting problem comes up :)
Sounds good! You can always catch us on Rewrite slack too if you'd like: https://join.slack.com/t/rewriteoss/shared_invite/zt-nj42n3ea-b~62rIHzb3Vo0E1APKCXEA
Hey!
I have a newbie question – does openwrite necessary need to be applied as a plugin to a Maven or Gradle project?
The number of applications that we maintain is growing and we'd like to be able to apply some refactors across all of them – without having to add openrewrite and, more importantly, the specific recipes to each individual Gradle project. Similar to how tools like fastmod, jscodeshift or comby can just work on any source code provided to them.
Are there any fundamental reasons why that wouldn't be possible with openrewrite? I realise that it analyses the AST, which may be making it difficult. On the other hand, jscodeshift works on AST as well (but JavaScript is an interpreted language...). Again, please forgive my ignorance as I'm new to Java. :)
To be concrete, we're looking at integrating openrewrite with a framework like batch changes - which works based on specs that define a series of container-based refactoring steps: https://docs.sourcegraph.com/batch_changes/how-tos/creating_a_batch_change#writing-a-batch-spec
For example:
Would appreciate any thoughts on whether what we're after is even close to being feasible!
Cheers, Konrad
CC: @igor-sakhankov @gastonfournier