build: 템플릿 밖에서 혼자 빌드·배포되는 Gradle 루트를 만든다

옮겨 온 메시징 19개 모듈은 템플릿의 src/settings.gradle·build-logic·
카탈로그·registry에 기대고 있어 이 repo만으로는 빌드되지 않는다.
repo 루트를 Gradle 루트로 하는 단독 빌드를 만든다.

- build-logic/: grpc-library main 2e880c7의 줄인 사본(템플릿
  22df3525에서 복사, 템플릿 2959eff0까지의 변경도 같은 내용)에서
  gRPC BOM 규칙(ca.grpc-platform-module)만 뺐다. 배포 플러그인
  ca.library-publishing과 서명 키 해석(SigningKeys)은 그대로다.
  출처·뺀 것·고친 것은 build-logic/UPSTREAM.md.
- settings.gradle·build.gradle·gradle.properties: group
  dev.cakit.messaging, 단계 태스크 ci·mainCheck·releaseCheck와
  배포(release·releaseRehearsal·verifySigningKey)는 grpc-library와
  같은 모양이다. 메시징만 다른 점: Buf가 없고, 성능 lane이 없고,
  mainCheck와 releaseCheck가 브로커 인증 증거 게이트
  (verifyMessagingCertificationEvidence)를 부른다. 템플릿은 이 게이트를
  따로 messaging-certification.yml로 돌렸다. 그 workflow는 지운다.
- config/: registry 19행(source_path만 messaging/<leaf>로), 메시징
  클래스만 남긴 SpotBugs 제외 목록, 이미지 셋(postgres-16, kafka,
  toxiproxy, 모두 digest 고정), checkstyle 사본.
- gradle/libs.versions.toml: 메시징이 쓰는 항목만(avro, cloudevents,
  protobuf 4.33.2, toxiproxy, jmh)과 kafka-clients가 끌고 오는 취약
  버전을 덮는 pinned-lz4-java·pinned-snappy-java.
- 저장소 계약 테스트: MessagingPublicSurfaceContractTest(템플릿
  app-bootstrap에서 이력째 옮김)와 새 MessagingSettingsOwnerContractTest
  (app.messaging 주인은 starter 하나)를 messaging-testkit의
  repositoryContractTest lane에 둔다. check에 들어가 PR 단계에서 돈다.
- messaging-kafka: 인증 manifest 경로를 새 배치로 고친다.

버린 대안: 계약 테스트를 build-logic 테스트로 두는 안. 빌드 플러그인
시험과 모듈 계약이 섞이고, 소스·build.gradle을 입력으로 선언하는
기존 lane 장치를 쓸 수 없다.

위험: 이 커밋 단독으로는 lockfile을 다시 쓰지 않았다(뒤 커밋에서
desktop에서 쓴다). 패키지는 아직 dev.caskeleton.messaging이다.

검증: desktop ./gradlew projects rc=0(19개 모듈 포함).

Refs: design-docs repo-structure/05-library-repos.md 4·10.3·13.1절
This commit is contained in:
DongHyeonka
2026-11-08 16:11:52 +09:00
parent f593229fda
commit 2e9298ec33
87 changed files with 13862 additions and 78 deletions
@@ -1,8 +1,7 @@
package dev.caskeleton.bootstrap.contract.messaging;
package dev.caskeleton.messaging.testkit.contract;
import static org.assertj.core.api.Assertions.assertThat;
import dev.caskeleton.bootstrap.contract.support.RepositoryContractResources;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
@@ -34,8 +33,8 @@ import org.junit.jupiter.api.Test;
*
* <p>So the rule is one-directional and mechanical: a vendor library named in a public or protected
* signature is declared {@code api}; one used only behind private members stays {@code
* implementation}. {@code src/platforms/messaging/AGENTS.md} states it as policy — this holds it to
* the source so the two cannot drift.
* implementation}. {@code messaging/AGENTS.md} states it as policy — this holds it to the source so
* the two cannot drift.
*
* <p>The libraries checked are the ones an adopter would otherwise have to reverse-engineer into
* their own build: broker clients, codec libraries, the metrics registry, the reactive facade.
@@ -327,7 +326,7 @@ class MessagingPublicSurfaceContractTest {
*/
private static Map<String, String> catalogModules() {
Map<String, String> modules = new LinkedHashMap<>();
Path catalog = repositoryRoot().resolve("src/gradle/libs.versions.toml");
Path catalog = repositoryRoot().resolve("gradle/libs.versions.toml");
if (!Files.isRegularFile(catalog)) {
return modules;
}
@@ -345,7 +344,7 @@ class MessagingPublicSurfaceContractTest {
}
private static List<Path> messagingLeaves() {
Path family = repositoryRoot().resolve("src/platforms/messaging");
Path family = repositoryRoot().resolve("messaging");
try (Stream<Path> children = Files.list(family)) {
return children
.filter(Files::isDirectory)
@@ -378,9 +377,6 @@ class MessagingPublicSurfaceContractTest {
}
private static Path repositoryRoot() {
// Gradle hands the root only to the lanes that declare the repository files as inputs; the
// plain `test` lane gets none, so a test that reads the repository without a lane tag fails
// here instead of going stale behind an up-to-date check (review 2026-11-01 08-03).
return RepositoryContractResources.fromSystemProperty().repositoryRoot();
return RepositoryRoot.fromSystemProperty();
}
}
@@ -0,0 +1,91 @@
package dev.caskeleton.messaging.testkit.contract;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
/**
* How many types in this library own the {@code app.messaging} settings namespace.
*
* <p>The namespace is shared on purpose with one consumer: the backend template's outbound adapter
* binds {@code app.messaging.producer-id} through a settings type of its own, and the starter's
* {@code MessagingSettings} owns everything else, {@code broker} included. Spring binds both — each
* takes the fields it declares. While the two lived in one repository a single source scan counted
* both (the template's {@code MessagingAuthorityContractTest}, MSG-INT-002). Now each repository
* holds its own half: here, exactly one owner. A second one inside the library is how a setting
* comes to mean two things to two halves of the same product. The prefix is part of this library's
* public contract; renaming it is a MAJOR change.
*/
@Tag("repository-contract")
class MessagingSettingsOwnerContractTest {
private static final Pattern MESSAGING_PREFIX =
Pattern.compile("@ConfigurationProperties\\(\\s*(prefix\\s*=\\s*)?\"app\\.messaging\"");
private static final Pattern MESSAGING_PREFIX_CONSTANT =
Pattern.compile("@ConfigurationProperties\\(prefix = MessagingSettings\\.PREFIX\\)");
/** A strictly bound owner names its tree in a constant rather than an annotation. */
private static final Pattern STRICT_BINDER_PREFIX =
Pattern.compile("String PREFIX\\s*=\\s*\"app\\.messaging\"");
@Test
@DisplayName("이 라이브러리에서 app.messaging의 주인은 starter의 MessagingSettings 하나다")
void theStarterSettingsAreTheOnlyOwner() {
// given
List<Path> sources = productionSources();
// when
List<String> owners =
sources.stream()
.filter(MessagingSettingsOwnerContractTest::ownsTheNamespace)
.map(path -> repositoryRoot().relativize(path).toString())
.toList();
// then
assertThat(owners)
.containsExactly(
"messaging/messaging-spring-boot-starter/src/main/java/dev/caskeleton/messaging/"
+ "autoconfigure/MessagingSettings.java");
}
private static boolean ownsTheNamespace(Path source) {
String text = read(source);
return MESSAGING_PREFIX.matcher(text).find()
|| MESSAGING_PREFIX_CONSTANT.matcher(text).find()
|| STRICT_BINDER_PREFIX.matcher(text).find();
}
private static List<Path> productionSources() {
try (Stream<Path> walk = Files.walk(repositoryRoot().resolve("messaging"))) {
return walk.filter(path -> path.toString().endsWith(".java"))
.filter(path -> path.toString().contains("/src/main/java/"))
.filter(path -> !path.toString().contains("/build/"))
.sorted()
.toList();
} catch (IOException unreadable) {
throw new UncheckedIOException(unreadable);
}
}
private static String read(Path path) {
try {
return Files.readString(path);
} catch (IOException unreadable) {
throw new UncheckedIOException(unreadable);
}
}
private static Path repositoryRoot() {
return RepositoryRoot.fromSystemProperty();
}
}
@@ -0,0 +1,50 @@
package dev.caskeleton.messaging.testkit.contract;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.List;
/**
* The repository root for the contract tests that read other modules' files.
*
* <p>Gradle passes it only to messaging-testkit's {@code repositoryContractTest} lane, which
* declares the files those tests read as its inputs. The plain {@code test} lane gets no root, so
* an untagged test that reads the repository fails here rather than passing on a stale up-to-date
* result. The same rule as the backend template's {@code RepositoryContractResources}, which these
* tests used while they lived there.
*/
final class RepositoryRoot {
static final String ROOT_PROPERTY = "ca.repository.root";
private static final List<String> ROOT_SENTINELS =
List.of("settings.gradle", "config/architecture/modules.json");
private RepositoryRoot() {}
static Path fromSystemProperty() {
String configured = System.getProperty(ROOT_PROPERTY);
if (configured == null || configured.isBlank()) {
throw new IllegalStateException(
"Required system property '"
+ ROOT_PROPERTY
+ "' is missing or blank. Only the repository-contract lane receives it: tag a test"
+ " that reads the repository with `repository-contract`.");
}
Path root;
try {
root = Path.of(configured).toRealPath();
} catch (InvalidPathException | IOException unresolvable) {
throw new IllegalStateException(
"Repository root is not resolvable: " + configured, unresolvable);
}
for (String sentinel : ROOT_SENTINELS) {
if (!Files.isRegularFile(root.resolve(sentinel))) {
throw new IllegalStateException(
"Configured repository root must contain " + ROOT_SENTINELS + ": " + root);
}
}
return root;
}
}