build.gradle.kts 2.49 KB
plugins {
    alias(libs.plugins.kotlin.jvm) apply false
    alias(libs.plugins.kotlin.spring) apply false
    alias(libs.plugins.kotlin.jpa) apply false
    alias(libs.plugins.spring.boot) apply false
    alias(libs.plugins.spring.dependency.management) apply false
}

allprojects {
    group = providers.gradleProperty("vibeerp.group").get()
    version = providers.gradleProperty("vibeerp.version").get()
}

// Enforce the architecture-level dependency rule (CLAUDE.md guardrail #9):
//
//   • PBCs may NEVER depend on other PBCs.
//     Cross-PBC interaction goes through api.v1 service interfaces or the
//     event bus.
//
//   • Plug-ins (and the reference plug-in) may ONLY depend on :api:api-v1.
//     They never see :platform:* or :pbc:* internals.
//
// The build fails at configuration time if either rule is violated.
gradle.projectsEvaluated {
    rootProject.allprojects.forEach { p ->
        val ownPath: String = p.path

        val checkedConfigs = listOf("api", "implementation", "compileOnly", "compileClasspath")
        val projectDeps = p.configurations
            .matching { it.name in checkedConfigs }
            .flatMap { cfg ->
                cfg.dependencies.filterIsInstance<org.gradle.api.artifacts.ProjectDependency>()
            }

        if (ownPath.startsWith(":pbc:")) {
            projectDeps.forEach { dep ->
                @Suppress("DEPRECATION")
                val depPath = dep.dependencyProject.path
                if (depPath.startsWith(":pbc:") && depPath != ownPath) {
                    throw GradleException(
                        "Architectural violation in $ownPath: depends on $depPath. " +
                            "PBCs MUST NOT depend on other PBCs. Use api.v1 service " +
                            "interfaces (org.vibeerp.api.v1.ext.<pbc>) or the event bus."
                    )
                }
            }
        }

        val isPlugin = ownPath.startsWith(":reference-customer:") ||
            ownPath.contains("plugin-")
        if (isPlugin) {
            projectDeps.forEach { dep ->
                @Suppress("DEPRECATION")
                val depPath = dep.dependencyProject.path
                if (depPath.startsWith(":platform:") || depPath.startsWith(":pbc:")) {
                    throw GradleException(
                        "Architectural violation in $ownPath: depends on internal module $depPath. " +
                            "Plug-ins may only depend on :api:api-v1."
                    )
                }
            }
        }
    }
}