From 6fe9034ac5fa528704ac399e653454b4b41f668e Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Fri, 20 Feb 2026 01:01:20 +0100 Subject: [PATCH 1/5] Start support for allowing all external libraries --- .../plugin/ModuleRestrictionScope.kt | 2 ++ .../plugin/ProjectGuardExtension.kt | 3 +- .../internal/ModuleRestrictionScopeImpl.kt | 7 +++++ .../plugin/internal/ModuleRestrictionSpec.kt | 1 + .../plugin/ProjectGuardExtensionTest.kt | 31 +++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt index 80abbc1..b7f7864 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt @@ -30,6 +30,8 @@ interface ModuleRestrictionScope { fun allow(vararg library: Provider) + fun allowExternalLibraries() + fun applyRule(rule: RestrictModuleRule) // Not sure this is a good idea, bundles can be updated without seeing what dependencies we are allowing diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtension.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtension.kt index 5cbfd60..0d8ab60 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtension.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtension.kt @@ -46,7 +46,8 @@ abstract class ProjectGuardExtension @Inject constructor( ModuleRestrictionSpec( modulePath = modulePath, reason = scope.getReason(), - allowed = scope.getAllowedDependencies() + allowed = scope.getAllowedDependencies(), + allowExternalLibraries = scope.areExternalLibrariesAllowed() ) ) } diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionScopeImpl.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionScopeImpl.kt index 5660e94..2d1e1fc 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionScopeImpl.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionScopeImpl.kt @@ -26,6 +26,7 @@ internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope { private val allowed = mutableListOf() private var restrictionReason = UNSPECIFIED_REASON + private var allowExternalLibraries = false override fun reason(reason: String) { restrictionReason = reason @@ -41,6 +42,10 @@ internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope { allow(modulePath = moduleDelegation.map { module -> module.path }.toTypedArray()) } + override fun allowExternalLibraries() { + allowExternalLibraries = true + } + override fun allow(vararg library: Provider) { allow(modulePath = library.map { lib -> lib.getDependencyPath() @@ -55,5 +60,7 @@ internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope { fun getReason() = restrictionReason + fun areExternalLibrariesAllowed() = allowExternalLibraries + } diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionSpec.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionSpec.kt index 2f88dc0..ce096ef 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionSpec.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionSpec.kt @@ -22,4 +22,5 @@ internal data class ModuleRestrictionSpec( val modulePath: String, val reason: String, val allowed: List, + val allowExternalLibraries: Boolean, ): Serializable diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtensionTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtensionTest.kt index d9026b1..422aca3 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtensionTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/ProjectGuardExtensionTest.kt @@ -60,6 +60,37 @@ class ProjectGuardExtensionTest { assertThat(restrictions.first().allowed.first().modulePath).isEqualTo("kotlin") } + @Test + fun `module restriction does not allow all external libraries by default`() { + // given + val extension = createExtension() + + // when + extension.restrictModule(":domain") + + // then + val spec = extension.getSpec() + val restrictions = spec.moduleRestrictionSpecs + assertThat(restrictions.first().allowExternalLibraries).isFalse() + } + + @Test + fun `module restriction can allow all external libraries`() { + // given + val extension = createExtension() + + // when + extension.restrictModule(":domain") { + allow(":feature") + allowExternalLibraries() + } + + // then + val spec = extension.getSpec() + val restrictions = spec.moduleRestrictionSpecs + assertThat(restrictions.first().allowExternalLibraries).isTrue() + } + @Test fun `extension correctly configures dependency restrictions`() { // given From 02b5fdc1ef3534b87c1cdef44cc962cd39c2ba70 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Fri, 20 Feb 2026 01:24:11 +0100 Subject: [PATCH 2/5] Do not count restrictions for external libraries if spec allows them --- .../plugin/internal/Dependency.kt | 7 +- .../plugin/internal/DependencyGraph.kt | 66 ++++++++----------- .../plugin/internal/DependencyGraphBuilder.kt | 20 ++---- .../internal/DependencyRestrictionFinder.kt | 5 +- .../internal/task/TaskDependencyDump.kt | 7 +- .../plugin/TaskAggregateDependencyDumpTest.kt | 2 +- .../internal/DependencyGraphBuilderTest.kt | 8 +-- .../plugin/internal/DependencyGraphTest.kt | 34 ++++++++-- .../plugin/internal/ModuleRestrictionTest.kt | 17 +++++ 9 files changed, 103 insertions(+), 63 deletions(-) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/Dependency.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/Dependency.kt index 070a723..2c35c0b 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/Dependency.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/Dependency.kt @@ -16,15 +16,20 @@ package com.rubensousa.projectguard.plugin.internal -internal sealed interface Dependency { +import java.io.Serializable + +internal sealed interface Dependency : Serializable { val id: String + val isLibrary: Boolean } internal data class DirectDependency( override val id: String, + override val isLibrary: Boolean, ) : Dependency internal data class TransitiveDependency( override val id: String, + override val isLibrary: Boolean, val path: List, ) : Dependency diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt index 7f1e3a3..4aea395 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt @@ -21,10 +21,20 @@ import java.io.Serializable internal class DependencyGraph : Serializable { private val configurations = mutableMapOf() - private val libraries = mutableSetOf() fun getConfigurations() = configurations.values.toList() + fun addDependency( + module: String, + dependency: DirectDependency, + configurationId: String = DependencyConfiguration.COMPILE, + ) { + val configuration = configurations.getOrPut(configurationId) { + Configuration(configurationId) + } + configuration.add(module = module, dependency = dependency) + } + fun addInternalDependency( module: String, dependency: String, @@ -32,26 +42,21 @@ internal class DependencyGraph : Serializable { ) { addDependency( module = module, - dependency = dependency, - configurationId = configurationId + dependency = DirectDependency(dependency, isLibrary = false), + configurationId = configurationId, ) } - fun addExternalDependency( + fun addLibraryDependency( module: String, dependency: String, configurationId: String = DependencyConfiguration.COMPILE, ) { addDependency( module = module, - dependency = dependency, + dependency = DirectDependency(dependency, isLibrary = true), configurationId = configurationId ) - libraries.add(dependency) - } - - fun isExternalLibrary(dependency: String): Boolean { - return libraries.contains(dependency) } fun getDependencies(module: String): List { @@ -72,27 +77,28 @@ internal class DependencyGraph : Serializable { while (queue.isNotEmpty()) { val currentTraversal = queue.removeFirst() val currentDependency = currentTraversal.dependency - if (visitedDependencies.contains(currentDependency)) { + if (visitedDependencies.contains(currentDependency.id)) { continue } - paths[currentDependency] = if (currentTraversal.path.isEmpty()) { - DirectDependency(currentDependency) + paths[currentDependency.id] = if (currentTraversal.path.isEmpty()) { + currentDependency } else { TransitiveDependency( - currentDependency, - currentTraversal.path + currentDependency + id = currentDependency.id, + isLibrary = currentDependency.isLibrary, + path = currentTraversal.path + currentDependency.id, ) } - visitedDependencies.add(currentDependency) + visitedDependencies.add(currentDependency.id) configurations.values.forEach { configuration -> // Search only for non-test configurations as they're not considered transitive at this point if (!DependencyConfiguration.isTestConfiguration(configuration.id)) { - configuration.getDependencies(currentDependency).forEach { nextDependency -> + configuration.getDependencies(currentDependency.id).forEach { nextDependency -> queue.addFirst( TraversalState( configurationId = configuration.id, dependency = nextDependency, - path = currentTraversal.path + currentDependency + path = currentTraversal.path + currentDependency.id ) ) } @@ -102,33 +108,22 @@ internal class DependencyGraph : Serializable { return paths.values.sortedBy { it.id } } - private fun addDependency( - module: String, - dependency: String, - configurationId: String, - ) { - val configuration = configurations.getOrPut(configurationId) { - Configuration(configurationId) - } - configuration.add(module = module, dependency = dependency) - } - private data class TraversalState( val configurationId: String, - val dependency: String, + val dependency: DirectDependency, val path: List, ) class Configuration(val id: String) : Serializable { - private val nodes = mutableMapOf>() + private val nodes = mutableMapOf>() - fun add(module: String, dependency: String) { + fun add(module: String, dependency: DirectDependency) { val existingDependencies = nodes.getOrPut(module) { mutableSetOf() } existingDependencies.add(dependency) } - fun getDependencies(module: String): Set { + fun getDependencies(module: String): Set { return nodes[module] ?: emptySet() } @@ -148,14 +143,11 @@ internal class DependencyGraph : Serializable { override fun equals(other: Any?): Boolean { return other is DependencyGraph - && other.libraries == this.libraries && other.configurations == this.configurations } override fun hashCode(): Int { - var result = configurations.hashCode() - result = 31 * result + libraries.hashCode() - return result + return configurations.hashCode() } diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt index 22ca7d2..cc323ce 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt @@ -28,19 +28,13 @@ internal class DependencyGraphBuilder { projectDump.modules.forEach { report -> report.configurations.forEach { configuration -> configuration.dependencies.forEach { dependency -> - if (dependency.isLibrary) { - graph.addExternalDependency( - configurationId = configuration.id, - module = report.module, - dependency = dependency.id, + graph.addDependency( + module = report.module, + dependency = DirectDependency( + id = dependency.id, + isLibrary = dependency.isLibrary ) - } else { - graph.addInternalDependency( - configurationId = configuration.id, - module = report.module, - dependency = dependency.id, - ) - } + ) } } } @@ -67,7 +61,7 @@ internal class DependencyGraphBuilder { } is ExternalModuleDependency -> { - graph.addExternalDependency( + graph.addLibraryDependency( module = moduleId, dependency = "${dependency.group}:${dependency.name}", configurationId = config.name diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionFinder.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionFinder.kt index 72bafe3..eb18a1d 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionFinder.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionFinder.kt @@ -89,7 +89,10 @@ internal class DependencyRestrictionFinder( dependency: Dependency, spec: ProjectGuardSpec, ) { - spec.moduleRestrictionSpecs.forEach { restriction -> + for (restriction in spec.moduleRestrictionSpecs) { + if (dependency.isLibrary && restriction.allowExternalLibraries) { + continue + } val matchesModule = hasModuleMatch( modulePath = moduleId, referencePath = restriction.modulePath diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/task/TaskDependencyDump.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/task/TaskDependencyDump.kt index 3072a5f..6a99340 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/task/TaskDependencyDump.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/task/TaskDependencyDump.kt @@ -71,8 +71,11 @@ internal class DependencyDumpExecutor( configurations = dependencyGraph.getConfigurations().map { configuration -> ConfigurationDependencies( id = configuration.id, - dependencies = configuration.getDependencies(moduleId).toList().map { dependencyId -> - DependencyReferenceDump(dependencyId, dependencyGraph.isExternalLibrary(dependencyId)) + dependencies = configuration.getDependencies(moduleId).map { dependency -> + DependencyReferenceDump( + id = dependency.id, + isLibrary = dependency.isLibrary + ) } ) } diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/TaskAggregateDependencyDumpTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/TaskAggregateDependencyDumpTest.kt index 1244aa9..14ce241 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/TaskAggregateDependencyDumpTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/TaskAggregateDependencyDumpTest.kt @@ -44,7 +44,7 @@ class TaskAggregateDependencyDumpTest { addInternalDependency(firstModule, firstDependency) } plugin.dumpDependencies(secondModule) { - addExternalDependency(module = secondModule, dependency = secondDependency) + addLibraryDependency(module = secondModule, dependency = secondDependency) } // when diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilderTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilderTest.kt index 6933cc9..ac90eea 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilderTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilderTest.kt @@ -57,8 +57,8 @@ class DependencyGraphBuilderTest { // then val compileConfiguration = graph.getConfigurations().find { it.id == DependencyConfiguration.COMPILE }!! - assertThat(compileConfiguration.getDependencies(consumerProject.path)) - .isEqualTo(setOf(legacyProjectA.path, legacyProjectB.path)) + assertThat(compileConfiguration.getDependencies(consumerProject.path).map { it.id }) + .containsExactly(legacyProjectA.path, legacyProjectB.path) } @Test @@ -72,8 +72,8 @@ class DependencyGraphBuilderTest { // then val testConfiguration = graph.getConfigurations().find { it.id == DependencyConfiguration.TEST }!! - assertThat(testConfiguration.getDependencies(consumerProject.path)) - .isEqualTo(setOf(legacyProjectA.path, legacyProjectC.path)) + assertThat(testConfiguration.getDependencies(consumerProject.path).map { it.id }) + .containsExactly(legacyProjectA.path, legacyProjectC.path) } private fun Project.addLegacyDependency(dependency: String): Project { diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphTest.kt index 056ab71..4dcac99 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphTest.kt @@ -134,8 +134,12 @@ class DependencyGraphTest { // then assertThat(dependencies).isEqualTo( listOf( - DirectDependency(consumerDependency), - TransitiveDependency(dependencyOfConsumerDependency, listOf(consumerDependency, dependencyOfConsumerDependency)) + DirectDependency(id = consumerDependency, isLibrary = false), + TransitiveDependency( + id = dependencyOfConsumerDependency, + isLibrary = false, + path = listOf(consumerDependency, dependencyOfConsumerDependency) + ) ) ) } @@ -163,7 +167,7 @@ class DependencyGraphTest { // then assertThat(dependencies).isEqualTo( listOf( - DirectDependency(consumerDependency), + DirectDependency(id = consumerDependency, isLibrary = false), ) ) } @@ -191,7 +195,7 @@ class DependencyGraphTest { // then assertThat(dependencies).isEqualTo( listOf( - DirectDependency(consumerDependency), + DirectDependency(id = consumerDependency, isLibrary = false), ) ) } @@ -215,4 +219,26 @@ class DependencyGraphTest { assertThat(graph).isEqualTo(deserializedGraph) } + @Test + fun `libraries are identified as such`() { + // given + val consumer = "consumer" + val consumerDependency = "dependencyA" + graph.addLibraryDependency( + configurationId = DependencyConfiguration.TEST, + module = consumer, + dependency = consumerDependency + ) + + // when + val dependencies = graph.getDependencies(consumer) + + // then + assertThat(dependencies).isEqualTo( + listOf( + DirectDependency(id = consumerDependency, isLibrary = true), + ) + ) + } + } diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionTest.kt index cad268f..3a978b6 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/ModuleRestrictionTest.kt @@ -177,4 +177,21 @@ class ModuleRestrictionTest { assertThat(restrictions).containsExactly(DirectDependencyRestriction(":legacy:a")) } + @Test + fun `restriction does not apply to external libraries if configured to do so`() { + // given + val spec = projectGuard { + restrictModule(":domain") { + allowExternalLibraries() + } + } + graph.addLibraryDependency(":domain:a", "datetime") + + // when + val restrictions = finder.find(moduleId = ":domain:a", spec = spec) + + // then + assertThat(restrictions).isEmpty() + } + } From 8935e3887b92c3d645fd9ffc76170535a39fa4db Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Fri, 20 Feb 2026 01:25:08 +0100 Subject: [PATCH 3/5] Update api file --- projectguard/api/projectguard.api | 1 + 1 file changed, 1 insertion(+) diff --git a/projectguard/api/projectguard.api b/projectguard/api/projectguard.api index 542bb99..cd0a124 100644 --- a/projectguard/api/projectguard.api +++ b/projectguard/api/projectguard.api @@ -28,6 +28,7 @@ public abstract interface class com/rubensousa/projectguard/plugin/ModuleRestric public abstract fun allow ([Ljava/lang/String;)V public abstract fun allow ([Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V public abstract fun allow ([Lorg/gradle/api/provider/Provider;)V + public abstract fun allowExternalLibraries ()V public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/RestrictModuleRule;)V public abstract fun reason (Ljava/lang/String;)V } From b99146422f36fc5870d0a9e2eb92510fd050f6ff Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Fri, 20 Feb 2026 01:34:50 +0100 Subject: [PATCH 4/5] Cleanup graph traversal --- .../plugin/internal/DependencyGraph.kt | 26 ++++++++----------- .../plugin/internal/DependencyRestriction.kt | 26 +------------------ 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt index 4aea395..6d9007d 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraph.kt @@ -69,7 +69,6 @@ internal class DependencyGraph : Serializable { TraversalState( configurationId = configuration.id, dependency = dependency, - path = emptyList() ) ) } @@ -80,15 +79,7 @@ internal class DependencyGraph : Serializable { if (visitedDependencies.contains(currentDependency.id)) { continue } - paths[currentDependency.id] = if (currentTraversal.path.isEmpty()) { - currentDependency - } else { - TransitiveDependency( - id = currentDependency.id, - isLibrary = currentDependency.isLibrary, - path = currentTraversal.path + currentDependency.id, - ) - } + paths[currentDependency.id] = currentDependency visitedDependencies.add(currentDependency.id) configurations.values.forEach { configuration -> // Search only for non-test configurations as they're not considered transitive at this point @@ -97,21 +88,26 @@ internal class DependencyGraph : Serializable { queue.addFirst( TraversalState( configurationId = configuration.id, - dependency = nextDependency, - path = currentTraversal.path + currentDependency.id + dependency = TransitiveDependency( + id = nextDependency.id, + isLibrary = nextDependency.isLibrary, + path = when (currentDependency) { + is DirectDependency -> listOf(currentDependency.id, nextDependency.id) + is TransitiveDependency -> currentDependency.path + nextDependency.id + }, + ) ) ) } } } } - return paths.values.sortedBy { it.id } + return paths.values.sortedBy { dependency -> dependency.id } } private data class TraversalState( val configurationId: String, - val dependency: DirectDependency, - val path: List, + val dependency: Dependency, ) class Configuration(val id: String) : Serializable { diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestriction.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestriction.kt index 06c43b7..8607def 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestriction.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestriction.kt @@ -26,8 +26,6 @@ internal sealed interface DependencyRestriction { return "module:$moduleId|dependency:${dependencyId}" } - fun getText(moduleId: String): String - companion object { fun from(dependency: Dependency, reason: String): DependencyRestriction { @@ -50,19 +48,7 @@ internal sealed interface DependencyRestriction { internal data class DirectDependencyRestriction( override val dependencyId: String, override val reason: String = UNSPECIFIED_REASON, -) : DependencyRestriction { - - override fun getText(moduleId: String): String { - return """ - | Dependency restriction found! - | Module -> $moduleId - | Match -> $dependencyId - | Module '$moduleId' cannot depend on '$dependencyId' - | Reason: $reason - """.trimMargin() - } - -} +) : DependencyRestriction internal data class TransitiveDependencyRestriction( override val dependencyId: String, @@ -70,16 +56,6 @@ internal data class TransitiveDependencyRestriction( override val reason: String = UNSPECIFIED_REASON, ) : DependencyRestriction { - override fun getText(moduleId: String): String { - return """ - | Transitive dependency restriction found! - | Module -> $moduleId - | Match -> $dependencyId from ${getPathToDependencyText()} - | Module '$moduleId' cannot depend on '$dependencyId' - | Reason: $reason - """.trimMargin() - } - fun getPathToDependencyText(): String { return pathToDependency.joinToString(separator = " -> ") { it } } From c20f0a9fbb8bd4e3c5ee3e1be2f4d9ad2656f82a Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Fri, 20 Feb 2026 01:36:18 +0100 Subject: [PATCH 5/5] Pass existing configuration id --- .../projectguard/plugin/internal/DependencyGraphBuilder.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt index cc323ce..3f264c7 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyGraphBuilder.kt @@ -33,7 +33,8 @@ internal class DependencyGraphBuilder { dependency = DirectDependency( id = dependency.id, isLibrary = dependency.isLibrary - ) + ), + configurationId = configuration.id ) } }