Skip to content

Add module rules baseline plugin - #340

Merged
fornewid merged 3 commits into
developfrom
module-rules
Sep 28, 2026
Merged

fornewid merged 3 commits into
developfrom
module-rules

Conversation

@fornewid

@fornewid fornewid commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Port of fornewid/baseline-sample#4, trimmed to what Moop uses.

moop.module.rules, applied to the root project, records module structure rule violations in module-rules.txt, one sorted line each:

  • hilt: <module>: Hilt applied outside :app and :impl modules.
  • impl: <module> -> <impl module>: a module other than :app depends on an :impl module.
  • layer: <module> -> <module>: a lower layer depends on a higher one (core < data < feature < app; modules outside the layers, such as :testing, are ignored).

./gradlew moduleRulesBaseline writes the file, and ./gradlew moduleRules fails with +/- lines and a re-baseline hint when it is out of date. moduleRules runs in CI and check.sh, and CHECK.md lists both commands.

Each module gets a moduleRulesViolations task that writes its own violations. The root tasks depend on these tasks by path, so every module is configured even with org.gradle.configureondemand=true.

Current baseline:

hilt: :core:kotlin
hilt: :feature:home:api
hilt: :testing
layer: :core:datetime -> :data:model

Left out compared to baseline-sample#4:

  • the moduleRules { } extension (baseline file and layer order are fixed; the file is module-rules.txt instead of module-rules-baseline.txt)
  • the ModuleInfo text format (each module writes its own violation lines instead)
  • the separate check/baseline task classes, the Baseline helper and # comments in the baseline
  • the root-only guard and the check lifecycle hook (the root project has no check task)
  • matching the app by com.android.application, -impl suffixes and the second Hilt plugin id (Moop has :app, :impl modules and one Hilt id)
  • the TestKit tests and the JUnit 5/Truth catalog entries (the unit tests use the existing JUnit 4 entry)

Verification

  • ./gradlew -p build-logic :module-rules:test: 4 unit tests pass (CI doesn't run build-logic tests).
  • ./gradlew -p build-logic :module-rules:validatePlugins passes with stricter validation enabled (cacheability and input normalization declared).
  • ./gradlew moduleRulesBaseline writes the same 4 lines as the unmodified port of baseline-sample#4, whose 45 tests passed in Moop.
  • ./gradlew moduleRules passes and reuses the configuration cache on the second run.
  • ./gradlew :moduleRules (root only, configure-on-demand, no configuration cache) recomputes all 36 module outputs after they were deleted.
  • Removing hilt: :testing from module-rules.txt fails with + hilt: :testing and the re-baseline hint.

πŸ€– Generated with Claude Code

https://claude.ai/code/session_01Upxj1FvQeDpycupKdPQHUZ

fornewid and others added 3 commits September 28, 2026 22:22
Record module structure rule violations (hilt, impl, layer) in
module-rules.txt with the moop.module.rules root plugin:
moduleRulesBaseline writes the file and moduleRules fails when it
is out of date. Run moduleRules in CI and check.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Upxj1FvQeDpycupKdPQHUZ
Apply moop.module.rules at the end of the root plugins block without a
comment, and drop mustRunAfter and the missing-baseline fallback that
nothing uses. Follow Gradle's task authoring guidance: declare
cacheability (@UntrackedTask, @DisableCachingByDefault) and input
normalization so strict validatePlugins passes, set update and
baselineFile through lazy properties instead of Task.project, and
describe the tasks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Upxj1FvQeDpycupKdPQHUZ
The per-module task writes the module's rule violations, not module
info, so name the task, its class and its output after that. Also move
declaredDependencies into ModuleRulesPlugin, its only user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Upxj1FvQeDpycupKdPQHUZ
@fornewid
fornewid merged commit d61b7d1 into develop Sep 28, 2026
1 check passed
@fornewid
fornewid deleted the module-rules branch September 28, 2026 23:54
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.

1 participant