Skip to content

ADFA-4816: Prune excluded dirs during Spotless traversal - #1564

Merged
hal-eisen-adfa merged 4 commits into
stagefrom
ADFA-4816-spotless-exclude-flox
Jul 23, 2026
Merged

ADFA-4816: Prune excluded dirs during Spotless traversal#1564
hal-eisen-adfa merged 4 commits into
stagefrom
ADFA-4816-spotless-exclude-flox

Conversation

@hal-eisen-adfa

@hal-eisen-adfa hal-eisen-adfa commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

spotlessCheck takes 12+ minutes on machines with an activated flox environment, and seconds elsewhere. Spotless targets use root-relative **/ globs with targetExclude(...), which filters matches after Gradle has already walked the whole tree — including flox/*/.flox/run/* symlinks into /nix/store (measured 8.8M files on Linux). The daemon OOMs.

Fixes ADFA-4816.

Fix

Convert each **/-glob block (java, kotlin, kotlinGradle, xml, misc) from target("**/glob") + targetExclude(...) to target(fileTree(rootDir) { include(...); exclude(...) }), so excludes prune directories during traversal instead of subtracting after the walk (FormatExtension does target.minus(targetExclude) post-walk).

Two things the naive fix gets wrong

Research against Spotless 8.8.0 + Gradle's walker corrected the ticket's proposed exclude list:

  1. dir/** does not prune — it descends and filters. Gradle's PathVisitor.preVisitDirectory returns SKIP_SUBTREE only when the exclude matches the directory node itself. flox/** matches flox's contents, so Gradle still walks in. Spotless's own auto-excludes use bare names for this reason. → excludes here use flox, **/.flox, **/.git, **/.gradle.
  2. **/build would drop real source. Source packages named build exist (e.g. app/src/main/java/.../actions/build/DebugAction.kt); bare **/build prunes them. → build outputs are excluded via each project's buildDirectory (exactly what Spotless does today), which never collide with src/.../build packages.

commonTargetExcludes moved onto the include-tree (prunes those large vendored dirs during the walk too). shell is unchanged — its targets are literal-prefixed, so Gradle already prunes without a full walk.

Behavior change

The two tracked flox/{base,local}/.flox/.gitignore files leave the misc target set. Both already conform (no leading spaces, no trailing whitespace, final newline), so the violation set is unchanged.

Verification (local, macOS)

  • ✅ Config resolves; spotlessCheck passes on a clean tree.
  • ✅ Still catches violations — flags trailing whitespace added to a tracked .kt under app/src/.
  • Source package named build is NOT droppedapp/src/main/java/.../actions/build/*.kt is still flagged when dirtied (proves buildOutputExcludes targets only real output dirs).
  • The Linux/nix-store speedup (acceptance criterion ADFA-319 - Welcome Screen Test #1, <1 min) is exercised by CI: .github/workflows/debug.yml runs flox activate -d flox/base -- ./gradlew spotlessCheck --no-daemon.

Out of scope (follow-ups from the ticket, to be filed separately)

Pre-push hook scoping to changed files; origin/stage ratchet-ref freshness; the dead Sentry Gradle plugin.

spotlessCheck took 12+ minutes on machines with an activated flox
environment. Spotless targets used root-relative **/ globs with
targetExclude(), which filters after Gradle has already walked the whole
tree -- including flox/*/.flox/run/* symlinks into /nix/store (millions of
files), OOM-ing the daemon.

Switch each **/-glob block (java, kotlin, kotlinGradle, xml, misc) to a
fileTree(rootDir) whose excludes prune directories during traversal.

Key details:
- Excludes use bare directory names (flox, **/.flox, **/.git, **/.gradle),
  not dir/**: Gradle prunes a subtree only when the exclude matches the
  directory node itself; dir/** matches contents and still descends.
- Build outputs are excluded via each project's buildDirectory (mirroring
  Spotless's own auto-exclude), not **/build -- source packages named
  build (e.g. .../actions/build) exist and **/build would drop them.
- commonTargetExcludes moved onto the include-tree so those large vendored
  dirs prune during the walk too. shell is unchanged (literal-prefixed
  targets already prune).

The two tracked flox/*/.flox/.gitignore files leave the misc target set;
both already conform, so the violation set is unchanged.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c24852eb-7926-4ab3-87a0-dd019a4f2479

📥 Commits

Reviewing files that changed from the base of the PR and between 2957113 and 806d5b1.

📒 Files selected for processing (1)
  • build.gradle.kts
🚧 Files skipped from review as they are similar to previous changes (1)
  • build.gradle.kts

📝 Walkthrough
  • Updated Spotless traversal to prune excluded directory subtrees during walking (notably flox plus VCS/Gradle hidden dirs like **/.git, **/.gradle, and **/.flox), significantly reducing slow, memory-intensive spotlessCheck runs in activated flox environments.
  • Refactored Java, Kotlin, Kotlin Gradle (.gradle.kts), XML, and misc targets to build their format scope with target(fileTree(rootDir) { include(...); exclude(...) }) via a shared spotlessTarget(...) helper, applying common excludes plus:
    • traversalExcludes for early subtree pruning
    • buildOutputExcludes derived from each subproject’s layout.buildDirectory (excluding Gradle outputs without using broad **/build patterns)
  • Preserved formatting behavior:
    • Kept the XML strings.xml exclusion under values*/ to avoid Eclipse WTP string splitting issues
    • Avoided broad build directory exclusions to retain formatting in source packages named build
  • Left the shell target configuration unchanged (still only formats .githooks/**/* and scripts/**/*, with the existing keystore targetExclude).
  • Risk/Best-practice: exclusion patterns now control both pruning and formatting scope—ensure buildOutputExcludes (based on layout.buildDirectory relative to rootDir) stays correct if module/build output locations change, otherwise Spotless could unintentionally skip formatting real sources.

Walkthrough

Spotless configuration centralizes traversal and build-output exclusions. Java, Kotlin, Gradle Kotlin script, XML, and miscellaneous targets now use fileTree(rootDir) while preserving the XML strings.xml exclusion.

Changes

Spotless target selection

Layer / File(s) Summary
Shared traversal and build-output exclusions
build.gradle.kts
Adds shared traversal and project build-output exclusions and provides a helper for constructing Spotless file trees.
File-tree formatting targets
build.gradle.kts
Refactors Java, Kotlin, Gradle Kotlin script, XML, and miscellaneous Spotless targets to use shared exclusions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit hops through files so neat,
With tidy paths beneath its feet.
Spotless prunes the dusty trails,
While build outputs hide their tails.
“Hop, format, and keep things bright!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: pruning excluded directories during Spotless traversal.
Description check ✅ Passed The description is detailed but clearly aligned with the Spotless traversal and exclusion changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-4816-spotless-exclude-flox

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
build.gradle.kts

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build.gradle.kts`:
- Around line 298-303: Update the target fileTree configuration to preserve
formatting for .gradle files while still excluding .gradle directories from
traversal. Replace the broad traversalExcludes entry affecting .gradle with a
directory-only exclusion, keeping the existing include("**/.gitignore",
"**/.gradle") behavior and other exclusions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 95753d8c-a4b7-4d94-aa08-4ebb59adce0d

📥 Commits

Reviewing files that changed from the base of the PR and between aade24f and ca85a38.

📒 Files selected for processing (1)
  • build.gradle.kts

Comment thread build.gradle.kts Outdated
hal-eisen-adfa and others added 2 commits July 22, 2026 18:55
.gradle is only ever a cache directory (already pruned via
traversalExcludes), never a formattable file, so including it in the
misc target did nothing. Removing it resolves the apparent
include/exclude contradiction (flagged in review). Behavior-neutral --
spotlessCheck output unchanged.
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
@hal-eisen-adfa
hal-eisen-adfa merged commit 1a92fb6 into stage Jul 23, 2026
4 checks passed
@hal-eisen-adfa
hal-eisen-adfa deleted the ADFA-4816-spotless-exclude-flox branch July 23, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants