pluginssection to apply the rewrite plugin to the project.
--add-exports. The workaround for this issue is to add explicit exports for packages used by rewrite's java parser.
org.gradle.jvmargsto include this content:
./gradlew rewriteDiscoverto see a listing of all the recipes available for execution. Initially this will list only the recipes built-in to OpenRewrite.
org.openrewrite.java.format.AutoFormatrecipe. This recipe will format the source code in the project according to the styles specified in the rewrite.yml file, or according to Jetbrains IntelliJ's default Java style if no other style is specified.
AutoFormatactivated we can now apply it to the project. Run:
git diff, or use your preferred IDE's diff viewer, to inspect the changes.
org.openrewrite.java.ChangePackagewill move Java classes between package names you specify and update references and imports accordingly. To rename the
org.springframework.samples.petclinic.veterinary, create a rewrite.yml file at the project root and give it these contents:
com.yourorg.VetToVeterinary. Now add it to the active recipe list:
./gradlew rewriteRunto perform the package relocation. Afterwards you'll see both that the sources in the vet package have been moved to the new directory, and references such as import statements have been updated accordingly.
./mvnw clean installor
./gradlew build. At this point you know how to configure and run any recipe included in rewrite itself.
rewritedependency on rewrite-spring
org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migrationrecipe as active.
./gradlew rewriteRunand observe that the project has been upgraded to Spring Boot 2 and the test classes are all updated to be JUnit 5 tests. If you're using Maven, the pom.xml will also have had the Spring dependencies updated, the Junit 4 dependency removed and Junit 5 dependencies added. OpenRewrite does not yet support automatic update of Gradle dependencies. Gradle users will have to manually make the corresponding changes.