Build-time coupling occurs when a change to one build subproject requires another, unchanged subproject to be recompiled and retested. Loose build-time coupling limits that ripple, shortening the wait for feedback and accelerating the deployment pipeline, especially in large codebases. section 4.3 section 4.6
This is distinct from design-time coupling, which concerns whether a change requires changes elsewhere. Build-time coupling can still force unrelated code to be retested even when no source change is needed there. section 4.1.1 section 6.3.4
A Gradle dependency graph
In a food-ordering application, changing the money subproject causes its tests and those of accounting and customer-management to run. Order-management is also retested because it has a transitive dependency on money. Changing customer-management instead affects customer-management and order-management, but not accounting or money. section 4.3.1
Figure 4.9 The dependencies between Gradle projects create build-time coupling. Changing money causes the other projects to be recompiled and retested but changing customer-management only requires customer-management and order-management to be recompiled and retested.
The dependency graph shows why changes to different subprojects have different rebuild and retest scopes. section 4.3.1
Reduce the affected build scope with two physical design choices:
- Have clients depend on a stable API build project rather than a frequently changing implementation project. Implementation changes then need not trigger client retesting. section 5.4.4
- Separate implementation code that does not need to be tested together. For example, put web and persistence in separate projects that both depend on domain; a web change then need not run the persistence tests. section 4.3.3 section 6.3.4
Incremental builds are necessary to benefit from a narrower dependency graph: the build tool must skip unaffected work. Splitting projects does not prevent changes to shared dependencies from propagating, and some coupling is inevitable. Parallel or clustered testing can also reduce elapsed time, but can be expensive and complex. section 5.4.4 section 6.3.1 section 4.6
Pay particular attention to build-time coupling in a large monolith, where a single codebase can make the deployment pipeline a bottleneck. It is generally less important within a relatively small microservice, though its build can still benefit from careful organization. section 4.3.3 section 3.2.4
