Repository navigation
test: verify module boundaries with Spring Modulith - #297
Merged
epugh merged 1 commit intoNov 24, 2026
Merged
Conversation
Add ModularityTests, which runs ApplicationModules.of(Main.class).verify() so that dependency cycles between the top-level feature packages, and any use of another module's internal sub-package, fail the build. The test also writes PlantUML module diagrams to build/spring-modulith-docs. Spring Modulith 2.1.3 (the line built against Spring Boot 4.1) is added as a test-only dependency: spring-modulith-bom in dependencyManagement and spring-modulith-starter-test in the test bundle. Nothing reaches productionRuntimeClasspath, so the bootJar, SBOM, binary LICENSE/NOTICE and native image are unchanged. The test is @DisabledInNativeImage since ArchUnit classpath scanning cannot run in the native test binary. The current structure already passes with no code changes. AGENTS.md gets a short rule: if the test fails, fix the dependency instead of weakening the test, and expose internal packages only explicitly in package-info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds a test that enforces the server's package boundaries, so neither contributors nor AI coding agents can erode them without noticing.
ModularityTestsruns Spring Modulith'sApplicationModules.of(Main.class).verify():verify()fails on (a) dependency cycles between modules and (b) any module using another module's internal sub-package types. The code already follows this layout: every package has apackage-info.java, and there are no cross-module sub-package imports and no cycles. No production code changes. This PR turns an existing convention into a build check.Why now: more of this code is written with coding agents, which readily take the shortest path, for example importing
indexing.documentcreator.*fromsearch. Review catches some of that. A failing test catches all of it, and its message tells the author (human or agent) exactly which dependency to fix.Test scope only. Modulith is not on
productionRuntimeClasspath, so the bootJar, the CycloneDX SBOM, the generated binary LICENSE/NOTICE and the native image are unchanged. The test is@DisabledInNativeImage, because ArchUnit classpath scanning can't run in thenativeTestbinary, the same treatment as the Mockito-based tests. It starts no Spring context and needs no Solr, so it runs in the plainunitTesttask too. Spring Modulith is Apache-2.0.Evidence
search/BoundaryProbe.javataking aJsonDocumentCreatorparameter compiles and builds green onmain.After: the same probe fails the build:
./gradlew buildpasses, 459 tests, 0 failures (ModularityTests: 2 tests, 0 skipped). Spotless, RAT and the binary-licence completeness gate all pass../gradlew dependencies --configuration productionRuntimeClasspath | grep -c modulith→0.indexing.documentcreatorimport is from insideindexing. A new top-level package (e.g.cluster/in feat(cluster): return get-cluster-status and list-configsets as records #295) just becomes a new module.Merge Danger
Door: two-way
Revert the commit to remove it: one test class, one BOM line, one catalog entry, one doc section.
Blast Radius: test-classpath
The only new effect is on future PRs: one that adds a cycle or an internal cross-module dependency now fails
testand must restructure or expose the package deliberately via@NamedInterfaceinpackage-info.java. The test classpath gainsspring-modulith-core/-test/-docs(with ArchUnit and jMolecules), plusspring-data-commonsandspring-txtransitively.spring-modulith-testregisters oneContextCustomizerFactory, and it only acts on@ApplicationModuleTestclasses, of which there are none. The full suite passes unchanged.🤖 Generated with Claude Code