fix(build-logic): 순수 모듈 testFixtures classpath도 순수성 검사에 넣는다

문제: 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
This commit is contained in:
DongHyeonka
2026-11-13 13:49:40 +09:00
parent 42d84d505e
commit b44aa49e7a
2 changed files with 137 additions and 0 deletions
@@ -26,6 +26,11 @@ public final class ArchitecturePlugin implements Plugin<Project> {
private static final List<String> APPLICATION_CLASSPATHS = private static final List<String> APPLICATION_CLASSPATHS =
List.of( List.of(
"compileClasspath", "runtimeClasspath", "testCompileClasspath", "testRuntimeClasspath"); "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<String> TEST_FIXTURES_CLASSPATHS =
List.of("testFixturesCompileClasspath", "testFixturesRuntimeClasspath");
@Override @Override
public void apply(Project project) { public void apply(Project project) {
@@ -171,6 +176,13 @@ public final class ArchitecturePlugin implements Plugin<Project> {
.getResolutionResult() .getResolutionResult()
.getRootComponent()); .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(); String applicationPath = module.gradlePath();
application application
.getTasks() .getTasks()
@@ -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"),
"""
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>%s</groupId><artifactId>%s</artifactId><version>1.0.0</version>
<packaging>pom</packaging>
</project>
"""
.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);
}
}