From 1d0adbd31b7fe1df4fe0eb2201b6466adbd1c14c Mon Sep 17 00:00:00 2001 From: Jeff Retz Date: Thu, 19 Feb 2026 22:15:33 +0100 Subject: [PATCH 1/4] allow modules and libs as vararg and support DelegatingProjectDependency --- .../plugin/DependencyRestrictionScope.kt | 6 +++-- .../plugin/ModuleRestrictionScope.kt | 9 +++---- .../DependencyRestrictionScopeImpl.kt | 17 ++++++------- .../internal/ModuleRestrictionScopeImpl.kt | 25 ++++++++----------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/DependencyRestrictionScope.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/DependencyRestrictionScope.kt index a0e6800..4805987 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/DependencyRestrictionScope.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/DependencyRestrictionScope.kt @@ -16,14 +16,16 @@ package com.rubensousa.projectguard.plugin +import org.gradle.api.internal.catalog.DelegatingProjectDependency + interface DependencyRestrictionScope { fun reason(reason: String) - fun allow(modulePath: String) + fun allow(vararg modulePath: String) - fun allow(modulePaths: List) + fun allow(vararg moduleDelegation: DelegatingProjectDependency) fun applyRule(rule: RestrictDependencyRule) 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 6aea7c8..80abbc1 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/ModuleRestrictionScope.kt @@ -17,19 +17,18 @@ package com.rubensousa.projectguard.plugin import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.internal.catalog.DelegatingProjectDependency import org.gradle.api.provider.Provider interface ModuleRestrictionScope { fun reason(reason: String) - fun allow(modulePath: String) + fun allow(vararg modulePath: String) - fun allow(library: Provider) + fun allow(vararg moduleDelegation: DelegatingProjectDependency) - fun allowModules(modulePaths: List) - - fun allowLibs(libraries: List>) + fun allow(vararg library: Provider) fun applyRule(rule: RestrictModuleRule) diff --git a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionScopeImpl.kt b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionScopeImpl.kt index 364778c..a4bbfd5 100644 --- a/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionScopeImpl.kt +++ b/projectguard/src/main/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionScopeImpl.kt @@ -18,6 +18,7 @@ package com.rubensousa.projectguard.plugin.internal import com.rubensousa.projectguard.plugin.DependencyRestrictionScope import com.rubensousa.projectguard.plugin.RestrictDependencyRule +import org.gradle.api.internal.catalog.DelegatingProjectDependency internal class DependencyRestrictionScopeImpl : DependencyRestrictionScope { @@ -28,18 +29,14 @@ internal class DependencyRestrictionScopeImpl : DependencyRestrictionScope { restrictionReason = reason } - override fun allow(modulePath: String) { - allowed.add( - ModuleAllowSpec( - modulePath = modulePath, - ) - ) + override fun allow(vararg modulePath: String) { + allowed.addAll(modulePath.map { path -> + ModuleAllowSpec(modulePath = path) + }) } - override fun allow(modulePaths: List) { - modulePaths.forEach { path -> - allow(path) - } + override fun allow(vararg moduleDelegation: DelegatingProjectDependency) { + allow(modulePath = moduleDelegation.map { module -> module.path }.toTypedArray()) } override fun applyRule(rule: RestrictDependencyRule) { 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 a38e5bc..5660e94 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 @@ -19,6 +19,7 @@ package com.rubensousa.projectguard.plugin.internal import com.rubensousa.projectguard.plugin.ModuleRestrictionScope import com.rubensousa.projectguard.plugin.RestrictModuleRule import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.internal.catalog.DelegatingProjectDependency import org.gradle.api.provider.Provider internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope { @@ -30,24 +31,20 @@ internal class ModuleRestrictionScopeImpl : ModuleRestrictionScope { restrictionReason = reason } - override fun allow(modulePath: String) { - allowed.add( - ModuleAllowSpec( - modulePath = modulePath, - ) - ) + override fun allow(vararg modulePath: String) { + allowed.addAll(modulePath.map { path -> + ModuleAllowSpec(modulePath = path) + }) } - override fun allowModules(modulePaths: List) { - modulePaths.forEach { path -> allow(path) } + override fun allow(vararg moduleDelegation: DelegatingProjectDependency) { + allow(modulePath = moduleDelegation.map { module -> module.path }.toTypedArray()) } - override fun allow(library: Provider) { - allow(library.getDependencyPath()) - } - - override fun allowLibs(libraries: List>) { - libraries.forEach { library -> allow(library) } + override fun allow(vararg library: Provider) { + allow(modulePath = library.map { lib -> + lib.getDependencyPath() + }.toTypedArray()) } override fun applyRule(rule: RestrictModuleRule) { From 107fc343597882dee0a533df6d794e76366af63f Mon Sep 17 00:00:00 2001 From: Jeff Retz Date: Thu, 19 Feb 2026 22:57:39 +0100 Subject: [PATCH 2/4] added example and updated api --- projectguard/api/projectguard.api | 11 +++++------ sample/build.gradle.kts | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/projectguard/api/projectguard.api b/projectguard/api/projectguard.api index 6fb782d..542bb99 100644 --- a/projectguard/api/projectguard.api +++ b/projectguard/api/projectguard.api @@ -3,8 +3,8 @@ public abstract interface class com/rubensousa/projectguard/plugin/DenyScope { } public abstract interface class com/rubensousa/projectguard/plugin/DependencyRestrictionScope { - public abstract fun allow (Ljava/lang/String;)V - public abstract fun allow (Ljava/util/List;)V + public abstract fun allow ([Ljava/lang/String;)V + public abstract fun allow ([Lorg/gradle/api/internal/catalog/DelegatingProjectDependency;)V public abstract fun applyRule (Lcom/rubensousa/projectguard/plugin/RestrictDependencyRule;)V public abstract fun reason (Ljava/lang/String;)V } @@ -25,10 +25,9 @@ public final class com/rubensousa/projectguard/plugin/GuardScope$Companion { } public abstract interface class com/rubensousa/projectguard/plugin/ModuleRestrictionScope { - public abstract fun allow (Ljava/lang/String;)V - public abstract fun allow (Lorg/gradle/api/provider/Provider;)V - public abstract fun allowLibs (Ljava/util/List;)V - public abstract fun allowModules (Ljava/util/List;)V + 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 applyRule (Lcom/rubensousa/projectguard/plugin/RestrictModuleRule;)V public abstract fun reason (Ljava/lang/String;)V } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 73dceca..dbfdc3f 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -28,6 +28,10 @@ projectGuard { // Test dependencies are fine allow(libs.junit) } + restrictModule(":feature") { + allow(":feature:a", ":feature:b") + allow(projects.feature.c, projects.feature.d) + } restrictDependency(":legacy") { reason("Legacy modules should no longer be used") From 9ca0c59fc2891757f094150a96e8f11e8c89cc5c Mon Sep 17 00:00:00 2001 From: Jeff Retz Date: Thu, 19 Feb 2026 23:15:49 +0100 Subject: [PATCH 3/4] fix tests --- .../projectguard/plugin/internal/DependencyRestrictionTest.kt | 2 +- .../projectguard/plugin/internal/ModuleRestrictionTest.kt | 2 +- sample/settings.gradle.kts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt index 387eaff..a3272d9 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt @@ -144,7 +144,7 @@ class DependencyRestrictionTest { // given val spec = projectGuard { restrictDependency(":legacy") { - allow(listOf(":legacy:a", ":legacy:b")) + allow("legacy:a", "legacy:b") } } 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 4d5bd96..cad268f 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 @@ -134,7 +134,7 @@ class ModuleRestrictionTest { // given val spec = projectGuard { restrictModule(":domain") { - allowModules(listOf(":domain:a", ":domain:b")) + allow(":domain:a", ":domain:b") } } diff --git a/sample/settings.gradle.kts b/sample/settings.gradle.kts index 482875f..9e6d6ce 100644 --- a/sample/settings.gradle.kts +++ b/sample/settings.gradle.kts @@ -28,6 +28,8 @@ dependencyResolutionManagement { } rootProject.name = "ProjectGuardSample" +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + include(":data:a") include(":data:b") include(":data:c") From fa83b65f38cfca3c4bb9e01ed3098d3152fc4ae3 Mon Sep 17 00:00:00 2001 From: Jeff Retz Date: Thu, 19 Feb 2026 23:30:16 +0100 Subject: [PATCH 4/4] added colon to fix final test --- .../projectguard/plugin/internal/DependencyRestrictionTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt index a3272d9..88eb7b9 100644 --- a/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt +++ b/projectguard/src/test/kotlin/com/rubensousa/projectguard/plugin/internal/DependencyRestrictionTest.kt @@ -144,7 +144,7 @@ class DependencyRestrictionTest { // given val spec = projectGuard { restrictDependency(":legacy") { - allow("legacy:a", "legacy:b") + allow(":legacy:a", ":legacy:b") } }