From 69202fe788c9117bb9e2cbbff09ddbdd57d1a9fa Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Tue, 17 Jan 2023 12:28:45 -0500 Subject: [PATCH 1/2] Following documentation on config cache https://docs.gradle.org/current/userguide/configuration_cache.html --- dependency-guard/build.gradle.kts | 2 +- .../dependencyguard/DependencyGuardPlugin.kt | 4 ++- .../internal/ConfigurationValidators.kt | 32 +++++++++---------- .../dependencyguard/internal/ProjectExt.kt | 5 +-- .../internal/list/DependencyGuardListTask.kt | 7 ++-- .../internal/tree/DependencyTreeDiffTask.kt | 1 + 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/dependency-guard/build.gradle.kts b/dependency-guard/build.gradle.kts index 536be96..5cf715a 100644 --- a/dependency-guard/build.gradle.kts +++ b/dependency-guard/build.gradle.kts @@ -88,7 +88,7 @@ testing { useJUnitJupiter() dependencies { // gradleTest test suite depends on the production code in tests - implementation(project) + implementation(project(project.path)) implementation(libs.truth) } diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/DependencyGuardPlugin.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/DependencyGuardPlugin.kt index 5391f56..3667b69 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/DependencyGuardPlugin.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/DependencyGuardPlugin.kt @@ -16,6 +16,8 @@ public class DependencyGuardPlugin : Plugin { internal companion object { internal const val DEPENDENCY_GUARD_TASK_GROUP = "Dependency Guard" + internal const val DEPENDENCY_GUARD_EXTENSION_NAME = "dependencyGuard" + internal const val DEPENDENCY_GUARD_TASK_NAME = "dependencyGuard" internal const val DEPENDENCY_GUARD_BASELINE_TASK_NAME = "dependencyGuardBaseline" @@ -23,7 +25,7 @@ public class DependencyGuardPlugin : Plugin { override fun apply(target: Project) { val extension = target.extensions.create( - DEPENDENCY_GUARD_TASK_NAME, + DEPENDENCY_GUARD_EXTENSION_NAME, DependencyGuardPluginExtension::class.java, target.objects ) diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ConfigurationValidators.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ConfigurationValidators.kt index 9ecb376..31d980d 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ConfigurationValidators.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ConfigurationValidators.kt @@ -27,23 +27,23 @@ internal object ConfigurationValidators { }.toString() throw GradleException(message) } - return - } - val configurationNames = monitoredConfigurations.map { it.configurationName } - require(configurationNames.isNotEmpty() && configurationNames[0].isNotBlank()) { - StringBuilder().apply { - appendLine("Error: No configurations provided to Dependency Guard Plugin.") - appendLine("Here are some valid configurations you could use.") - appendLine("") - val availableConfigNames = availableConfigurations - .filter { isClasspathConfig(it) } + } else { + val configurationNames = monitoredConfigurations.map { it.configurationName } + require(configurationNames.isNotEmpty() && configurationNames[0].isNotBlank()) { + StringBuilder().apply { + appendLine("Error: No configurations provided to Dependency Guard Plugin.") + appendLine("Here are some valid configurations you could use.") + appendLine("") + val availableConfigNames = availableConfigurations + .filter { isClasspathConfig(it) } - appendLine("dependencyGuard {") - availableConfigNames.forEach { - appendLine(""" configuration("$it")""") - } - appendLine("}") - }.toString() + appendLine("dependencyGuard {") + availableConfigNames.forEach { + appendLine(""" configuration("$it")""") + } + appendLine("}") + }.toString() + } } } diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ProjectExt.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ProjectExt.kt index db0c911..7acd5ef 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ProjectExt.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/ProjectExt.kt @@ -4,6 +4,7 @@ import com.dropbox.gradle.plugins.dependencyguard.DependencyGuardPlugin import org.gradle.api.Project import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.result.ResolvedComponentResult +import org.gradle.api.provider.Provider internal fun Project.isRootProject(): Boolean = this == rootProject @@ -19,8 +20,8 @@ internal val Project.projectConfigurations: ConfigurationContainer configurations } -internal fun ConfigurationContainer.getResolvedComponentResult(name: String): ResolvedComponentResult = this +internal fun ConfigurationContainer.getResolvedComponentResult(name: String): Provider = this .getByName(name) .incoming .resolutionResult - .root \ No newline at end of file + .rootComponent \ No newline at end of file diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/list/DependencyGuardListTask.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/list/DependencyGuardListTask.kt index 792a7f0..b4a0b4c 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/list/DependencyGuardListTask.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/list/DependencyGuardListTask.kt @@ -21,6 +21,7 @@ import org.gradle.api.artifacts.result.ResolvedComponentResult import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction @@ -57,7 +58,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() { abstract val projectPath: Property @get:Input - abstract val monitoredConfigurationsMap: MapProperty + abstract val monitoredConfigurationsMap: MapProperty> @get:Input abstract val buildDirectory: DirectoryProperty @@ -70,7 +71,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() { internal fun execute() { val dependencyGuardConfigurations = monitoredConfigurationsMap.get() - val reports = dependencyGuardConfigurations.map { generateReportForConfiguration(it.key, it.value) } + val reports = dependencyGuardConfigurations.map { generateReportForConfiguration(it.key, it.value.get()) } // Throw Error if any Disallowed Dependencies are Found val reportsWithDisallowedDependencies = reports.filter { it.disallowed.isNotEmpty() } @@ -184,7 +185,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() { private fun resolveMonitoredConfigurationsMap( project: Project, monitoredConfigurations: Collection, - ): Map { + ): Map> { val configurationContainer = project.projectConfigurations return monitoredConfigurations.associateWith { diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/tree/DependencyTreeDiffTask.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/tree/DependencyTreeDiffTask.kt index da20e9e..5fb1872 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/tree/DependencyTreeDiffTask.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/tree/DependencyTreeDiffTask.kt @@ -10,6 +10,7 @@ import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.artifacts.result.ResolvedComponentResult import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction From 6859e7652b0c3ef31300bae1df4d52699032159e Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Mon, 23 Jan 2023 10:15:36 -0500 Subject: [PATCH 2/2] Update Changelog and drop support for Gradle 7.3. --- CHANGELOG.md | 7 +++++++ dependency-guard/build.gradle.kts | 2 +- .../dependencyguard/GradleVersionArgumentsProvider.kt | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e61849..807ac88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## Version 0.4.1 ([All Changes](https://github.com/dropbox/dependency-guard/compare/0.4.0...0.4.1)) + +_2023-01-23_ + +* Fixes [#67](https://github.com/dropbox/dependency-guard/issues/67): Configuration Cache by [@handstandsam](https://github.com/handstandsam) in [#70](https://github.com/dropbox/dependency-guard/pull/70) +* Compatibility: **Requires Gradle 7.4 or Higher** in order to support Configuration Cache. + ## Version 0.4.0 ([All Changes](https://github.com/dropbox/dependency-guard/compare/0.3.2...0.4.0)) _2023-01-17_ diff --git a/dependency-guard/build.gradle.kts b/dependency-guard/build.gradle.kts index 5cf715a..536be96 100644 --- a/dependency-guard/build.gradle.kts +++ b/dependency-guard/build.gradle.kts @@ -88,7 +88,7 @@ testing { useJUnitJupiter() dependencies { // gradleTest test suite depends on the production code in tests - implementation(project(project.path)) + implementation(project) implementation(libs.truth) } diff --git a/dependency-guard/src/gradleTest/kotlin/com/dropbox/gradle/plugins/dependencyguard/GradleVersionArgumentsProvider.kt b/dependency-guard/src/gradleTest/kotlin/com/dropbox/gradle/plugins/dependencyguard/GradleVersionArgumentsProvider.kt index 472366b..41af95f 100644 --- a/dependency-guard/src/gradleTest/kotlin/com/dropbox/gradle/plugins/dependencyguard/GradleVersionArgumentsProvider.kt +++ b/dependency-guard/src/gradleTest/kotlin/com/dropbox/gradle/plugins/dependencyguard/GradleVersionArgumentsProvider.kt @@ -10,7 +10,6 @@ class GradleVersionArgumentsProvider : ArgumentsProvider { override fun provideArguments(context: ExtensionContext?): Stream = Stream .of( - ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.3.3"), withConfigurationCache = false), ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.4.2"), withConfigurationCache = false), ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.4.2"), withConfigurationCache = true), ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.5.1"), withConfigurationCache = false),