Skip to content

Commit 6fc824b

Browse files
gnodetclaude
andcommitted
chore: conditionally enable OpenRewrite per module via marker files
Instead of always running OpenRewrite on all modules (which adds ~8 min to every build), use Maven file-activated profiles to run it only on modules with changed Java files. Before the build, regen.sh creates .rewrite-enabled marker files in modules that have modified Java files. The rewrite profile in parent/pom.xml activates when this file exists, so OpenRewrite runs only where needed. This approach is recipe-agnostic — adding new OpenRewrite recipes to the profile requires no changes to the detection logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 22a687b commit 6fc824b

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ mvnd.zip*
3333
backlog
3434
.claude
3535
.omc
36-
.oss-ai-helper-rules
36+
.oss-ai-helper-rules
37+
.rewrite-enabled

etc/scripts/regen.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ cd `dirname "$0"`/../..
2525
git clean -fdx
2626
rm -Rf **/src/generated/
2727

28+
# Enable OpenRewrite only for modules with changed Java files.
29+
# Maven's file-activated profile (<exists>.rewrite-enabled</exists>) checks
30+
# per-module, so OpenRewrite runs only where needed — no -Prewrite flag required.
31+
# We only need --deepen=1 (depth 1 -> 2) since we compare adjacent commits:
32+
# for PRs, HEAD~1 is the base branch tip (first parent of the merge commit);
33+
# for main builds, HEAD~1 is the previous squash-merged commit.
34+
if ! git rev-parse HEAD~1 >/dev/null 2>&1; then
35+
git fetch --deepen=1 --quiet 2>/dev/null || true
36+
fi
37+
38+
if git rev-parse HEAD~1 >/dev/null 2>&1; then
39+
git diff HEAD~1 HEAD --name-only -- '*.java' ':!*/src/generated/*' \
40+
| sed 's|/src/.*||' | sort -u \
41+
| while read module; do
42+
[ -d "$module" ] && touch "$module/.rewrite-enabled"
43+
done
44+
fi
45+
2846
# Regenerate everything
2947
if ./mvnw --batch-mode -Pregen -DskipTests ${MAVEN_EXTRA_ARGS} install >> build.log 2>&1; then
3048
echo "✅ mvn -Pregen succeeded."

parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4183,6 +4183,11 @@
41834183

41844184
<profile>
41854185
<id>rewrite</id>
4186+
<activation>
4187+
<file>
4188+
<exists>.rewrite-enabled</exists>
4189+
</file>
4190+
</activation>
41864191
<build>
41874192
<plugins>
41884193
<plugin>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
${maven.multiModuleProjectDirectory}/buildingtools/src/main/resources/header.txt
262262
</header>
263263
<excludes>
264+
<exclude>**/.rewrite-enabled</exclude>
264265
<exclude>release.properties</exclude>
265266
<exclude>**/pom.xml.tag</exclude>
266267
<exclude>**/pom.xml.releaseBackup</exclude>

0 commit comments

Comments
 (0)