Video in progress
Moving from Spring Boot 2 to 3 needs a mechanical change that touches all the code, such as `javax.*` → `jakarta.*`. How do you handle this on the Git side without breaking the team's open PRs?
I turn the mechanical part into a recipe that can be rerun (OpenRewrite) and land it as a separate "mechanical only" commit in an agreed window. Owners of open PRs run that recipe on their own branch, then merge the mechanical commit with -s ours, so there are almost no conflicts.
📖 Answer
The problem: the moment a commit touching 600 files lands on main, each of the 15 open PRs gets dozens of conflicts. People resolve them by hand and make mistakes.
My plan:
- Separate the mechanical work from the manual work. Boot 3 requires Java 17, and some HQL and type mappings changed in Hibernate 6. Those are separate, ordinary PRs. The mechanical commit contains only the automatic rewrite.
- A deterministic recipe:
The recipe and its version are written down in the repo so that everyone gets the same result../mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run \ -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE \ -Drewrite.activeRecipes=org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta - A window. Announced in advance: until that day, as many PRs as possible get merged. Then the mechanical commit M lands.
- Instructions for the remaining PRs:
The recipe has already been applied on the branch, and M is exactly the same change, so "swallowing" it withgit merge M^ # update the branch to the state before M # run the recipe on your own branch, commit git merge -s ours M # M is marked as "merged", the code does not change git merge origin/main # the ordinary changes after Moursis correct. If the recipe is not deterministic, this method does not work. - Blame. M's hash is added to
.git-blame-ignore-revs. - Preventing regressions. In CI, run the recipe in
rewrite:dryRunmode: if someone brings ajavaximport back from an old branch, the build fails.
The same approach works for big formatting changes (turning Spotless on for the whole repo) or package renames. The main idea: a person should not resolve conflicts by hand, a machine should regenerate the change.
Sign up to mark studied questions and save your progress.