Files
clean-architecture-backend-…/src/build.gradle
T
DongHyeonka 2678955c64 build(quality)!: 테스트 코드 정적 분석을 게이트에 넣고 발견을 고친다
문제: qualityCheck는 spotbugsMain만 돈다. main 밖 source set(test,
testFixtures, integrationTest, systemTest 등)의 SpotBugs 태스크 111개는
어느 게이트에도 없었고, 돌려 보니 53개가 실패했다(발견 300건). 그중
동시성 테스트 7건은 CountDownLatch.await의 시간 초과를 무시하고 다음
단계로 가서 순서를 확인하지 않은 채 통과했다. 2개는 분석 classpath에
없는 클래스 때문에 분석이 불완전했다.

방법:
- leaf마다 testQualityCheck를 두고 main 빌드는 mainCheck, optional 빌드는
  ci에 넣었다. PR 게이트에 넣지 않은 것은 테스트 코드가 배포되지 않고
  전체 실행이 ci만큼 걸려서다.
- 테스트용 제외 목록 config/spotbugs/exclude-test.xml. 패턴 전체 제외는
  이유가 모든 테스트 클래스에 성립하는 것만(보안 범주, 내부 상태 노출,
  생성자 예외, 반환값 null 역참조, 아키텍처 위반 fixture). 나머지 30건은
  클래스·메서드로 좁히고 이유를 달았다.
- 24건은 코드로 고쳤다: await 결과 단언, 공유 변수 원자성, 닫지 않은
  Statement, SQLException을 삼키던 upsert 테스트, 만료 없는 키에서 NPE가
  나던 Redis fake. 쓰는 곳이 없던 web-fileserver 테스트 helper 2개는
  지웠다.
- 모든 SpotBugs 태스크가 그 source set의 runtime classpath로 분석하고
  분석이 불완전하면 실패한다. SpotBugs 플러그인이 나중에 생긴 source
  set의 태스크를 등록하면서 classpath를 덮어써서 설정을 평가 뒤에
  등록한다. 그 자리에 의존성을 더하는 우회는 버렸다.

위험·한계: 파생 서비스는 자기 테스트 코드의 SpotBugs 발견이 mainCheck를
막는다(업그레이드 안내 B-40). mainCheck가 그만큼 길어진다(main 빌드 테스트
태스크 100개).

검증: ci, 두 빌드 verifyStrictLaneStages --dry-run, mainCheck(testQualityCheck
100개 포함, 3분 10초 → 8분 33초), :integrationCheck, -p optional-platforms
ci(testQualityCheck 포함) integrationCheck performanceCheck,
:performanceCheck, :releaseCheck(-PgitRevision), verify-compose-profile-
contracts(18 lane) 첫 실행 통과. 고친 컨테이너 테스트는 클래스별로 따로
실행해 통과.

Refs: docs/reviews/2026-11-03-rereview/README.md 14절
BREAKING CHANGE: mainCheck(optional 빌드는 ci)가 테스트 source set의
SpotBugs·FindSecBugs 발견에 실패한다. 고치거나 config/spotbugs/
exclude-test.xml에 이유를 단 좁은 Match를 더한다.
2026-11-04 08:11:15 +09:00

238 lines
13 KiB
Groovy

plugins {
// Spring Boot stays on the root build script classpath because two leaves apply it by id
// (`app-bootstrap`, `sample-portfolio`) and a leaf resolves plugin classes from the root.
//
// Spotless, SpotBugs, Error Prone and Spring's dependency-management are NOT here any more. They
// were declared `apply false` for a `configure(subprojects)` block that applied them to every
// leaf; build-logic's `ca.quality-conventions` and `ca.java-conventions` apply them now, and a
// plugin reachable from two classpaths is two versions waiting to differ. Their versions are the
// same catalog entries either way — build-logic/settings.gradle reads gradle/libs.versions.toml.
alias(libs.plugins.spring.boot) apply false
// JMH benchmarks in three leaves (`./gradlew :<leaf>:jmh`); never part of a gate.
alias(libs.plugins.jmh) apply false
// Convention plugin from the included build, applied to the ROOT because the rules it owns are
// about the repository: the architecture gates. The release version/revision is each leaf's
// `ca.java-conventions` (ca.release-provenance was removed, BUILD-O3-5). The public-path
// baseline is app-bootstrap's approval test, the local start-up is scripts/bootstrap-local.sh,
// and archive hygiene is gone with the revision it cleaned out of every leaf's jar name (review
// 2026-09-24 BUILD-O3-5).
id 'ca.architecture'
// Every strict lane belongs to a stage a workflow executes (review 2026-11-01 08-01).
id 'ca.strict-lane-stages'
}
group = 'dev.caskeleton'
// A release archive has to name the commit that produced it. The revision rule is the one every
// leaf's version uses (JavaConventionsPlugin.sourceRevision, tested in build-logic), read here so
// the tag-only gate and the jars cannot disagree about what counts as a commit id.
tasks.register('verifyReleaseProvenance') {
group = 'verification'
description = 'Fails when the build cannot name the source revision it was produced from.'
String revision = dev.caskeleton.buildlogic.java.JavaConventionsPlugin.sourceRevision(providers)
boolean traceable = revision != dev.caskeleton.buildlogic.java.JavaConventionsPlugin.UNKNOWN_REVISION
outputs.upToDateWhen { false }
doLast { task ->
if (!traceable) {
throw new GradleException('verifyReleaseProvenance: no source revision. A release archive has to name the '
+ 'commit that produced it; supply -PgitRevision=<sha>, GIT_SHA or GITHUB_SHA.')
}
task.logger.lifecycle("verifyReleaseProvenance: OK — revision ${revision}")
}
}
// One explicit command regenerates every module's Gradle-default lockfile.
tasks.register('resolveAndLockAll') {
group = 'build setup'
description = 'Regenerates dependency locks for all subprojects (requires --write-locks).'
dependsOn subprojects.findAll { it.childProjects.isEmpty() }.collect { "${it.path}:resolveAndLockAll" }
}
tasks.register('verifyDependencyLocks') {
group = 'verification'
description = 'Verifies strict dependency lock state for production CI subprojects.'
dependsOn subprojects.findAll {
it.childProjects.isEmpty() && it.path != ':sample-portfolio'
}.collect { "${it.path}:verifyDependencyLocks" }
}
// feature-developer-experience-contract D3 — the ordered local bootstrap lifecycle is
// scripts/bootstrap-local.sh (compile, Docker preflight, dependency wait, migrate-and-start, smoke).
// ---------------------------------------------------------------------------------------------
// Lifecycle.
//
// :<leaf>:check that leaf — compile, its tests, Spotless, Checkstyle, Error Prone
// check every leaf's check (Gradle matches the name across projects)
// architectureCheck dependency direction + purity + app-bootstrap whole-repository ArchUnit
// qualityCheck SpotBugs + FindSecBugs across every leaf (ca.quality-conventions)
// ci the pull-request gate: leaf checks + architectureCheck + qualityCheck
// mainCheck the main-branch stage: environment contract, full-boot qualification,
// sample web contract, public-path baseline, transport and messaging
// qualification lanes, each leaf's document-contract lanes, and the
// feature generator round trip (verifyFeatureScaffold)
// integrationCheck the declared strict integration lanes (several need a container runtime)
// performanceCheck the declared strict performance lanes (load, shutdown, pool and resource
// bounds; real servers and containers)
// releaseCheck the tag-only checks: release provenance + public path snapshot (not `ci`
// again — a tag is cut from a main commit the PR and main stages ran on)
//
// A leaf's check is that leaf's; a repository question gets a repository task named after it.
// Task PATHS, not TaskProviders: a leaf's tasks are created by convention plugins after the root is
// evaluated, and a path is resolved when the task graph is built.
// ---------------------------------------------------------------------------------------------
List<String> leafPaths = subprojects.findAll {
it.childProjects.isEmpty() && it.path != ':sample-portfolio'
}.collect { it.path }.toSorted()
tasks.register('qualityCheck') {
group = 'verification'
description = 'Runs SpotBugs and FindSecBugs across every production CI leaf.'
dependsOn leafPaths.collect { "${it}:qualityCheck" }
}
tasks.register('configContractCheck') {
group = 'verification'
description = 'Runs the environment contract owned by the composition root.'
dependsOn ':app-bootstrap:verifyEnvKeys'
}
// A lane that needs an input this build was not given (the Redis topology coordinates, the protected
// AWS sandbox authority) is explicit-only: the aggregate leaves it out and names it when it runs
// (review NEW-16). The sample's integration lanes are here although the sample is not a production
// leaf, because nothing else ran its strict PostgreSQL lanes (review NEW-13e).
tasks.register('integrationCheck') {
group = 'verification'
description = "Runs every production CI leaf's and the sample's integration-category test lanes. Several need a container runtime."
dependsOn leafPaths.collect { "${it}:integrationTestLaneCheck" }
dependsOn ':sample-portfolio:integrationTestLaneCheck'
}
// Performance lanes are not the pull request's or the main stage's: their bounds need a machine that
// is not compiling something else. integration-main.yml runs this aggregate on main and nightly.
tasks.register('performanceCheck') {
group = 'verification'
description = "Runs every production CI leaf's performance-category test lanes. Several need a container runtime."
dependsOn leafPaths.collect { "${it}:performanceTestLaneCheck" }
}
tasks.named('architectureCheck') {
dependsOn leafPaths.collect { "${it}:architectureTestLaneCheck" }
}
// app-bootstrap is left out: its `check` already runs its full-boot lane in the pull-request gate,
// and the main stage ran the same lane a second time on every main push (review 2026-11-01 08-02).
// The lane stays merge-blocking, because a composition that does not boot must not merge.
tasks.register('systemTestCheck') {
group = 'verification'
description = "Runs every production CI leaf's full application/system test lanes that `ci` does not already run."
dependsOn leafPaths.findAll { it != ':app-bootstrap' }.collect { "${it}:systemTestLaneCheck" }
}
tasks.register('qualificationCheck') {
group = 'verification'
description = 'Runs repository/build-behavior qualification that is intentionally outside local leaf checks.'
dependsOn tasks.named('systemTestCheck')
dependsOn leafPaths.collect { "${it}:auxiliaryStyleCheck" }
dependsOn tasks.named('testQualityCheck')
}
// SpotBugs + FindSecBugs over every leaf's test source sets, against config/spotbugs/exclude-test.xml.
// Main stage, not `ci`: test code does not ship, and the full run is about as long as `ci` itself.
// It ran in no stage until 2026-11-04, and 53 of these tasks had been failing unseen.
tasks.register('testQualityCheck') {
group = 'verification'
description = 'Runs SpotBugs and FindSecBugs over every leaf\'s test source sets.'
dependsOn leafPaths.collect { "${it}:testQualityCheck" }
dependsOn ':sample-portfolio:testQualityCheck'
}
tasks.register('sampleWebContractCheck') {
group = 'verification'
description = 'Runs the real-server sample HTTP/OpenAPI contract source set without pulling every sample lane into CI.'
dependsOn ':sample-portfolio:webSystemTest'
}
// The feature generator's round trip (review 2026-11-01 개선 순서 4): scripts/new-feature.sh writes
// two features into a throwaway copy of the working tree and that copy's own Gradle runs the leaf
// checks they touch plus architectureCheck. A nested build of five leaves, so the main stage, not
// the pull request. The script is the whole check; this task only gives it a stage.
tasks.register('verifyFeatureScaffold', Exec) {
group = 'verification'
description = 'Generates features with scripts/new-feature.sh in a scratch copy and runs the gates they must pass.'
workingDir = rootProject.projectDir.parentFile
commandLine 'bash', 'scripts/verify-feature-scaffold.sh'
}
// Each lane below names its tests and rejects skips; these two only aggregate them.
tasks.register('conditionalTransportQualification') {
group = 'verification'
description = 'Runs the no-skip GraphQL, gRPC and WebSocket transport lanes and the opt-in classpath contract.'
dependsOn ':adapter:inbound:graphql:graphqlTransportQualificationTest',
':adapter:inbound:grpc:grpcTransportQualificationTest',
':adapter:inbound:websocket:websocketTransportQualificationTest',
':app-bootstrap:conditionalTransportBuildContractTest'
}
tasks.register('verifyMessagingContracts') {
group = 'verification'
description = 'Qualifies the application integration-event contract and the shared envelope schema.'
dependsOn ':application-core:messagingApplicationContractQualificationTest',
':shared-contract:messagingSharedSchemaQualificationTest',
':sample-portfolio:messagingSampleContractQualificationTest'
}
tasks.register('ci') {
group = 'verification'
description = 'The pull-request gate: every production CI leaf check plus the architecture and quality gates.'
dependsOn leafPaths.collect { "${it}:check" }
dependsOn tasks.named('architectureCheck')
dependsOn tasks.named('qualityCheck')
}
tasks.register('mainCheck') {
group = 'verification'
description = 'The main-branch stage: the gates that are not worth a pull request\'s wait.'
dependsOn leafPaths.collect { "${it}:mainCheck" }
dependsOn tasks.named('configContractCheck')
dependsOn tasks.named('qualificationCheck')
dependsOn tasks.named('sampleWebContractCheck')
// The standalone sample booted whole against real PostgreSQL. The sample is outside `leafPaths`,
// so systemTestCheck does not reach it, and no stage ran it (review 2026-11-01 08-01).
dependsOn ':sample-portfolio:systemTest'
dependsOn tasks.named('verifyPublicPathSnapshot')
dependsOn tasks.named('conditionalTransportQualification')
dependsOn tasks.named('verifyMessagingContracts')
dependsOn ':adapter:inbound:graphql:graphqlStableTest'
dependsOn tasks.named('verifyFeatureScaffold')
}
// The stages a strict lane may belong to. `verifyStrictLaneStages --dry-run` (pull-request gate)
// fails when a strict lane that is not `explicitOnly` is in the plan of none of these, or when a
// stage is executed by no workflow — the gap that left fourteen lanes running nowhere while each
// one failed closed (review 2026-11-01 08-01). A new lane joins a stage through its category
// aggregate; no workflow line names it.
strictLaneStages {
stage ':ci', ':sample-portfolio:check', ':mainCheck', ':integrationCheck', ':performanceCheck',
':releaseCheck'
workflowDirectory = layout.projectDirectory.dir('../.github/workflows')
}
// The deny-by-default public path baseline: app-bootstrap's approval-test lane under its old name.
// `-PapprovePublicPathChange` rewrites the baseline after review.
tasks.register('verifyPublicPathSnapshot') {
group = 'verification'
description = 'Fails when the shipped public path default drifts from docs/security/public-paths-snapshot.txt.'
dependsOn ':app-bootstrap:publicPathSnapshotTest'
}
// The checks that only matter for a release artifact. Not `ci` again: a release tag is cut from a
// main commit that the pull-request gate and the main stage already ran on (review BUILD-중복-6).
tasks.register('releaseCheck') {
group = 'verification'
description = 'The tag-only checks: release provenance and the public path baseline.'
dependsOn tasks.named('verifyReleaseProvenance')
dependsOn tasks.named('verifyPublicPathSnapshot')
}