openrewrite / rewrite

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

New recipe: AddRewriteRecipe to maven plugin configuration #1287

Open murdos opened 2 years ago

murdos commented 2 years ago

It's a bit meta, but I would be useful to have a maven recipe that allows adding a specific recipe automatically, conditioned by the presence of a specific dependency in classpath. As a bonus, until https://github.com/openrewrite/rewrite-maven-plugin/issues/229 is solved, the dependency in classpath could be added as dependency of the maven plugin for the recipe to be usable.

timtebeek commented 11 months ago

For a while we had init and configure goals on the rewrite-maven-plugin; sounds like those somewhat achieved what's asked here. I'd thought to provide that as context here.

The init and configure goals have been removed in favor of running the rewrite plugin with direct arguments that set the active recipe and recipe artifact coordinates, as seen here: https://docs.openrewrite.org/recipes/java/spring/boot3/upgradespringboot_3_1

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE \
  -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1

Could that help serve as an alternative to this recipe option? Since folks are unlikely to need to change their pom.xml nowadays.