refactor(layout)!: Gradle 루트와 계층 폴더를 옮긴다(옮기기만)

문제: Gradle 루트가 src/라서 빌드 도구(build-logic, gradle, config, 빌드
파일)가 계층 코드 폴더 옆에 섞여 있다. composition과 app-bootstrap은 같은
조립 계층인데 폴더가 따로이고, application 모듈 넷은 최상위에 흩어져 있다.
「Gradle은 src/에서 실행」이라는 예외 규칙이 모든 문서와 스크립트에 퍼졌다.

고른 방법: 저장소 루트를 Gradle 루트로 하고 src/에는 계층 코드만 둔다
(design-docs repo-structure/01-backend-layout.md 6.1절 가-2·가-3, 소유자
승인 2026-11-07). 이 커밋은 git mv만 한다. 이름 바꾸기 감지가 1541개
파일 모두를 R100으로 잡도록 내용을 바꾸지 않았다. 바뀐 곳은 둘뿐이다:
src/.gitignore의 줄을 루트 .gitignore로 옮겼다.

- 빌드 파일, gradle/, build-logic/ → 저장소 루트
- config/checkstyle·spotbugs → config/ (코드 검사 도구 설정만)
- registry config/architecture/modules.json → gradle/modules.json,
  시험 이미지 config/testing/container-images.properties
  → gradle/container-images.properties, registry 설명 → gradle/README.md
- Dockerfile, .dockerignore, .env*.example → 저장소 루트
- src/README.md(빌드·env 참조) → docs/build.md
- src/domain-core → src/domain/core,
  src/application-* → src/application/*,
  src/app-bootstrap → src/bootstrap/app,
  src/composition/* → src/bootstrap/*
- 기능 생성 템플릿 scripts/feature-scaffold/{templates,probes}/src/ 아래도
  같은 모양으로(domain/core, application/core, bootstrap/app)

위험: 이 커밋만으로는 빌드되지 않는다. 경로를 부르는 곳은 다음 커밋이
고친다. 두 커밋을 나눈 것은 파생 서비스가 merge할 때 이름 바꾸기와 내용
변경을 따로 보게 하려는 것이다.

검증: git diff --cached -M --name-status 에서 R100 1541개, 그 밖은
.gitignore 수정과 src/.gitignore 삭제뿐.

BREAKING CHANGE: 모든 빌드 파일과 계층 폴더의 경로가 바뀐다. 옛 경로 →
새 경로 표와 받는 순서는 docs/upgrade/2026-11-relayout.md에 있다.
Refs: design-docs repo-structure/01-backend-layout.md 6.1절
This commit is contained in:
DongHyeonka
2026-11-11 21:04:21 +09:00
parent 66eaa98202
commit 1388c06a9f
1543 changed files with 16 additions and 22 deletions
@@ -0,0 +1,340 @@
package dev.caskeleton.buildlogic.architecture;
import dev.caskeleton.buildlogic.ModuleRegistry;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
public final class ArchitecturePlugin implements Plugin<Project> {
private static final List<String> PRODUCTION_DECLARATIONS =
List.of("api", "implementation", "compileOnly", "runtimeOnly");
private static final List<String> APPLICATION_CLASSPATHS =
List.of(
"compileClasspath", "runtimeClasspath", "testCompileClasspath", "testRuntimeClasspath");
@Override
public void apply(Project project) {
Project root = project.getRootProject();
// The Gradle root (src/) owns the registry; the repository root is its parent, and every
// source_path in the registry is relative to the repository root.
File mainBuildDirectory = root.getProjectDir();
File registryFile = new File(mainBuildDirectory, "config/architecture/modules.json");
File repositoryRoot = mainBuildDirectory.getParentFile();
ModuleRegistry registry = ModuleRegistry.read(registryFile, repositoryRoot);
List<ModuleRegistry.Module> modules = registry.modulesForBuild("main");
List<String> registryViolations = registryViolations(registry, modules);
var clean =
project
.getTasks()
.register(
"verifyCleanArchitectureDependencies",
VerifyCleanArchitectureDependenciesTask.class,
task -> {
task.setGroup("verification");
task.setDescription("Verifies Clean Architecture project dependency direction.");
task.getRegistryFile().fileValue(registryFile);
task.getRegistryViolations().set(registryViolations);
task.getUnregisteredBuildScripts()
.set(registry.unregisteredBuildScripts(root.getProjectDir()));
});
var purity =
project
.getTasks()
.register(
"verifyApplicationCoreDependencyPurity",
task -> {
task.setGroup("verification");
task.setDescription(
"Verifies domain-core, shared-contract and every application-* module have only"
+ " project production dependencies and no framework on their classpaths.");
});
var ignoredSources =
project
.getTasks()
.register(
"verifyNoIgnoredSourcePackages",
VerifyNoIgnoredSourcePackagesTask.class,
task -> {
task.setGroup("verification");
task.setDescription(
"Fails when a Java source file lives in a package that Git ignores or would"
+ " ignore.");
task.getBuildRoot().set(root.getLayout().getProjectDirectory());
});
project
.getGradle()
.projectsEvaluated(
ignored -> {
Set<String> declaredModules = new HashSet<>();
root.getSubprojects().stream()
.filter(sub -> sub.getChildProjects().isEmpty())
.forEach(sub -> declaredModules.add(sub.getPath().replaceFirst("^:", "")));
// One task per module, registered in the project that owns the configurations. The
// root task used to walk every other project and resolve its `compileClasspath`,
// which asks Gradle for state another project holds the lock on — with
// `org.gradle.parallel=true` that is a hard failure, and it is why the flag was
// turned off instead of the verification moved.
List<String> moduleTaskPaths = new ArrayList<>();
for (ModuleRegistry.Module module : modules) {
Project owner = root.project(module.gradlePath());
Set<String> allowed = new HashSet<>();
for (String dependencyId : module.allowedDependencies()) {
ModuleRegistry.Module dependency = registry.byId(dependencyId);
if (dependency != null) {
allowed.add(dependency.gradlePath().replaceFirst("^:", ""));
}
}
Set<String> declaredEdges = declaredProjectEdges(owner);
Set<String> declaredLibraries =
declaredLibraryEdges(owner, registry.libraryGroups());
Provider<ResolvedComponentResult> compileClasspathRoot =
owner
.getConfigurations()
.getByName("compileClasspath")
.getIncoming()
.getResolutionResult()
.getRootComponent();
String moduleName = module.gradlePath().replaceFirst("^:", "");
owner
.getTasks()
.register(
"verifyModuleDependencyDirection",
VerifyModuleDependencyDirectionTask.class,
task -> {
task.setGroup("verification");
task.setDescription(
"Verifies this module's declared and compile-visible project edges"
+ " against the architecture registry.");
task.getModuleName().set(moduleName);
task.getAllowedDependencies().set(allowed);
task.getDeclaredProjectEdges().set(declaredEdges);
task.getLibraryGroups().set(registry.libraryGroups());
task.getAllowedLibraries().set(module.allowedLibraries());
task.getDeclaredLibraryEdges().set(declaredLibraries);
task.getCompileClasspathRoot().set(compileClasspathRoot);
});
moduleTaskPaths.add(module.gradlePath() + ":verifyModuleDependencyDirection");
}
clean.configure(
task -> {
task.getDeclaredModules().set(declaredModules);
task.getGovernedModules()
.set(
modules.stream()
.map(module -> module.gradlePath().replaceFirst("^:", ""))
.toList());
task.dependsOn(moduleTaskPaths);
});
// Same ownership rule as the direction check: the task that resolves a pure
// module's classpaths lives in that module. domain-core and shared-contract are pure
// too (HS1): without them a framework dependency added there passed the build and
// was caught only if some class happened to import it.
List<String> purityTaskPaths = new ArrayList<>();
for (ModuleRegistry.Module module : modules) {
if (!isPure(module.id())) {
continue;
}
Project application = root.project(module.gradlePath());
Map<String, List<String>> production = new LinkedHashMap<>();
for (String name : PRODUCTION_DECLARATIONS) {
Configuration configuration = application.getConfigurations().findByName(name);
if (configuration != null) {
production.put(name, productionDeclarations(configuration));
}
}
Map<String, Provider<ResolvedComponentResult>> classpathRoots =
new LinkedHashMap<>();
for (String name : APPLICATION_CLASSPATHS) {
classpathRoots.put(
name,
application
.getConfigurations()
.getByName(name)
.getIncoming()
.getResolutionResult()
.getRootComponent());
}
String applicationPath = module.gradlePath();
application
.getTasks()
.register(
"verifyModuleDependencyPurity",
VerifyApplicationCoreDependencyPurityTask.class,
task -> {
task.setGroup("verification");
task.setDescription(
"Verifies this application module declares only project production"
+ " dependencies and carries no diagnostic framework.");
task.getModulePath().set(applicationPath);
task.getProductionDeclarations().set(production);
classpathRoots.forEach(
(name, rootComponent) ->
task.getResolvedClasspathRoots().put(name, rootComponent));
});
purityTaskPaths.add(module.gradlePath() + ":verifyModuleDependencyPurity");
}
purity.configure(task -> task.dependsOn(purityTaskPaths));
// Every source set of every project — testFixtures, integrationTest, systemTest and
// the sample included — because a file Git drops is lost whichever lane owns it.
// Directories under a build directory are generated and never committed.
List<File> sourceRoots = new ArrayList<>();
for (Project sub : root.getSubprojects()) {
SourceSetContainer sourceSets =
sub.getExtensions().findByType(SourceSetContainer.class);
if (sourceSets == null) {
continue;
}
Path buildDirectory = sub.getLayout().getBuildDirectory().get().getAsFile().toPath();
for (SourceSet sourceSet : sourceSets) {
for (File sourceRoot : sourceSet.getJava().getSrcDirs()) {
if (!sourceRoot.toPath().startsWith(buildDirectory)) {
sourceRoots.add(sourceRoot);
}
}
}
}
ignoredSources.configure(task -> task.getSourceRoots().from(sourceRoots));
});
project
.getTasks()
.register(
"architectureCheck",
task -> {
task.setGroup("verification");
task.setDescription("Runs the build's architecture invariants.");
task.dependsOn(clean, purity, ignoredSources);
});
}
private static boolean isPure(String moduleId) {
return moduleId.startsWith("application-")
|| moduleId.equals("domain-core")
|| moduleId.equals("shared-contract");
}
/**
* This module's declared {@code project(...)} edges, read while the owning project is configured.
*
* <p>Read here rather than in the task action: a {@link Configuration} cannot be stored in the
* configuration cache, and every declaration this reads is final by {@code projectsEvaluated}.
*/
private static Set<String> declaredProjectEdges(Project owner) {
Set<String> edges = new TreeSet<>();
for (String name : PRODUCTION_DECLARATIONS) {
Configuration configuration = owner.getConfigurations().findByName(name);
if (configuration == null) {
continue;
}
configuration
.getDependencies()
.withType(ProjectDependency.class)
.forEach(dependency -> edges.add(dependency.getPath().replaceFirst("^:", "")));
}
return edges;
}
/**
* This module's declared dependencies on an owned library ({@code group:artifact}, the group under
* one of the registry's {@code library_groups}), read the same way and from the same production
* configurations as the project edges, {@code runtimeOnly} included.
*/
private static Set<String> declaredLibraryEdges(Project owner, List<String> libraryGroups) {
Set<String> edges = new TreeSet<>();
if (libraryGroups.isEmpty()) {
return edges;
}
for (String name : PRODUCTION_DECLARATIONS) {
Configuration configuration = owner.getConfigurations().findByName(name);
if (configuration == null) {
continue;
}
configuration
.getDependencies()
.withType(ExternalModuleDependency.class)
.forEach(
dependency -> {
if (ModuleRegistry.isOwnedGroup(libraryGroups, dependency.getGroup())) {
edges.add(dependency.getGroup() + ":" + dependency.getName());
}
});
}
return edges;
}
/**
* One production configuration's declarations, tagged by kind.
*
* <p>The tag, not a filter, is what is captured: deciding which kind is a violation is the purity
* task's rule, and moving it here would put the rule in the collector.
*/
private static List<String> productionDeclarations(Configuration configuration) {
List<String> declarations = new ArrayList<>();
configuration
.getDependencies()
.forEach(
dependency -> {
if (dependency instanceof ProjectDependency projectDependency) {
declarations.add(
VerifyApplicationCoreDependencyPurityTask.PROJECT_DECLARATION
+ ":"
+ projectDependency.getPath());
} else {
String group = dependency.getGroup() == null ? "<no-group>" : dependency.getGroup();
declarations.add("module:" + group + ":" + dependency.getName());
}
});
return List.copyOf(declarations);
}
private static List<String> registryViolations(
ModuleRegistry registry, List<ModuleRegistry.Module> modules) {
List<String> violations = new ArrayList<>();
for (ModuleRegistry.Module module : modules) {
// The layers stay free of the owner's libraries by the registry itself, not only because the
// purity check happens to refuse every non-project declaration in them.
if (isPure(module.id()) && !module.allowedLibraries().isEmpty()) {
violations.add(
"'"
+ module.id()
+ "' is a layer module (domain-core, shared-contract, application-*) and may allow no"
+ " library, but allows "
+ module.allowedLibraries());
}
for (String dependencyId : module.allowedDependencies()) {
if (dependencyId.equals(module.id())) {
violations.add("'" + module.id() + "' declares itself as an allowed dependency");
continue;
}
ModuleRegistry.Module dependency = registry.byId(dependencyId);
if (dependency == null) {
violations.add(
"'" + module.id() + "' allows unknown dependency id '" + dependencyId + "'");
} else if (!dependency.buildName().equals(module.buildName())) {
violations.add(
"'" + module.id() + "' allows cross-build dependency id '" + dependencyId + "'");
}
}
}
return List.copyOf(violations);
}
}