From b44aa49e7abfcbb6eb159b03f1dd7898b1072d3d Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 08:40:23 +0900 Subject: [PATCH] =?UTF-8?q?fix(build-logic):=20=EC=88=9C=EC=88=98=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=20testFixtures=20classpath=EB=8F=84=20?= =?UTF-8?q?=EC=88=9C=EC=88=98=EC=84=B1=20=EA=B2=80=EC=82=AC=EC=97=90=20?= =?UTF-8?q?=EB=84=A3=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: verifyModuleDependencyPurity는 순수 모듈(application-*, domain-core, shared-contract)의 compile·runtime·test classpath만 풀어 봤다. test classpath는 testFixturesImplementation을 거쳐 보지만 testFixturesCompileOnly는 보지 않는다. 그래서 공유 fixtures에 Spring을 compileOnly로 두면 순수성 검사를 통과했다. testFixtures를 쓰는 순수 leaf 다섯 곳에 같은 구멍이 있었다. 고친 것: java-test-fixtures를 쓴 순수 모듈은 testFixturesCompileClasspath· testFixturesRuntimeClasspath도 같은 금지 group으로 본다. 지금 다섯 leaf의 fixtures에는 금지 group이 없어 기존 빌드는 그대로 통과한다(lockfile 대조). 검증: desktop, 기준 4ca61cd9 + 새 functional 시험만 → testFixturesCompileOnly Spring 케이스가 빌드 통과로 실패(RED). 고친 뒤 -p build-logic test 통과(다음 커밋의 GREEN 실행에 포함). Refs: RR9-04-47 --- .../architecture/ArchitecturePlugin.java | 12 ++ ...oduleTestFixturesPurityFunctionalTest.java | 125 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 build-logic/src/test/java/dev/caskeleton/buildlogic/architecture/PureModuleTestFixturesPurityFunctionalTest.java diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/architecture/ArchitecturePlugin.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/architecture/ArchitecturePlugin.java index 4e5491b4..34e2d3e7 100644 --- a/build-logic/src/main/java/dev/caskeleton/buildlogic/architecture/ArchitecturePlugin.java +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/architecture/ArchitecturePlugin.java @@ -26,6 +26,11 @@ public final class ArchitecturePlugin implements Plugin { private static final List APPLICATION_CLASSPATHS = List.of( "compileClasspath", "runtimeClasspath", "testCompileClasspath", "testRuntimeClasspath"); + // Present only where a pure module applies java-test-fixtures. The test classpaths above see + // testFixturesImplementation, but not testFixturesCompileOnly: a framework declared there + // compiled into the shared fixtures and passed the purity check. + private static final List TEST_FIXTURES_CLASSPATHS = + List.of("testFixturesCompileClasspath", "testFixturesRuntimeClasspath"); @Override public void apply(Project project) { @@ -171,6 +176,13 @@ public final class ArchitecturePlugin implements Plugin { .getResolutionResult() .getRootComponent()); } + for (String name : TEST_FIXTURES_CLASSPATHS) { + Configuration fixtures = application.getConfigurations().findByName(name); + if (fixtures != null) { + classpathRoots.put( + name, fixtures.getIncoming().getResolutionResult().getRootComponent()); + } + } String applicationPath = module.gradlePath(); application .getTasks() diff --git a/build-logic/src/test/java/dev/caskeleton/buildlogic/architecture/PureModuleTestFixturesPurityFunctionalTest.java b/build-logic/src/test/java/dev/caskeleton/buildlogic/architecture/PureModuleTestFixturesPurityFunctionalTest.java new file mode 100644 index 00000000..00517d81 --- /dev/null +++ b/build-logic/src/test/java/dev/caskeleton/buildlogic/architecture/PureModuleTestFixturesPurityFunctionalTest.java @@ -0,0 +1,125 @@ +package dev.caskeleton.buildlogic.architecture; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.gradle.testkit.runner.BuildResult; +import org.gradle.testkit.runner.GradleRunner; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** The purity check covers a pure module's test fixtures, not only its main and test classpaths. */ +class PureModuleTestFixturesPurityFunctionalTest { + + @Test + @DisplayName("순수 모듈의 testFixturesCompileOnly에 Spring을 두면 순수성 검사가 실패한다") + void aFrameworkInAPureModulesFixturesFailsThePurityCheck(@TempDir Path temporaryRoot) + throws IOException { + // given + Path project = + fixture( + temporaryRoot, "testFixturesCompileOnly 'org.springframework:spring-context:1.0.0'"); + + // when + BuildResult result = runner(project, "verifyApplicationCoreDependencyPurity").buildAndFail(); + + // then + assertThat(result.getOutput()) + .contains("testFixturesCompileClasspath: forbidden resolved dependency") + .contains("org.springframework:spring-context:1.0.0"); + } + + @Test + @DisplayName("순수 모듈의 testFixtures가 framework를 쓰지 않으면 순수성 검사를 통과한다") + void pureFixturesPassThePurityCheck(@TempDir Path temporaryRoot) throws IOException { + // given + Path project = fixture(temporaryRoot, "testFixturesImplementation 'org.example:other:1.0.0'"); + + // when + BuildResult result = runner(project, "verifyApplicationCoreDependencyPurity").build(); + + // then + assertThat(result.getOutput()).contains("verifyApplicationCoreDependencyPurity: OK"); + } + + private static Path fixture(Path temporaryRoot, String fixturesDeclaration) throws IOException { + Path project = temporaryRoot.resolve("repository"); + Files.createDirectories(project.resolve("gradle")); + Files.createDirectories(project.resolve("application-demo")); + Path maven = temporaryRoot.resolve("maven"); + pom(maven, "org.springframework", "spring-context"); + pom(maven, "org.example", "other"); + Files.writeString( + project.resolve("settings.gradle"), + """ + rootProject.name = 'main' + include 'application-demo' + """, + UTF_8); + Files.writeString( + project.resolve("build.gradle"), + """ + plugins { id 'ca.architecture' } + subprojects { + apply plugin: 'java-library' + apply plugin: 'java-test-fixtures' + repositories { maven { url = '%s' } } + } + project(':application-demo') { + dependencies { + %s + } + } + """ + .formatted(maven.toUri(), fixturesDeclaration), + UTF_8); + Files.writeString( + project.resolve("gradle/modules.json"), + """ + { + "library_groups": ["dev.cakit"], + "modules": [ + { + "id": "application-demo", + "gradle_path": ":application-demo", + "source_path": "application-demo", + "allowed_dependencies": [] + } + ] + } + """, + UTF_8); + return project; + } + + private static void pom(Path maven, String group, String artifact) throws IOException { + Path directory = maven.resolve(group.replace('.', '/')).resolve(artifact).resolve("1.0.0"); + Files.createDirectories(directory); + Files.writeString( + directory.resolve(artifact + "-1.0.0.pom"), + """ + + 4.0.0 + %s%s1.0.0 + pom + + """ + .formatted(group, artifact), + UTF_8); + } + + private static GradleRunner runner(Path project, String... arguments) { + String[] fullArguments = new String[arguments.length + 2]; + fullArguments[0] = "--console=plain"; + fullArguments[1] = "--stacktrace"; + System.arraycopy(arguments, 0, fullArguments, 2, arguments.length); + return GradleRunner.create() + .withProjectDir(project.toFile()) + .withPluginClasspath() + .withArguments(fullArguments); + } +}