From 92910c8b7cdc1665d720d2d802ef618d62f7d6c4 Mon Sep 17 00:00:00 2001 From: Tony Robalik Date: Sun, 17 Oct 2021 17:52:21 -0700 Subject: [PATCH] LocateDependenciesTask can be up to date. --- .editorconfig | 4 +-- ...ConfigurationsToDependenciesTransformer.kt | 7 ++--- .../internal/utils/gradleStrings.kt | 2 +- .../autonomousapps/subplugin/ProjectPlugin.kt | 21 ++++++-------- .../tasks/LocateDependenciesTask.kt | 29 +++++++++---------- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.editorconfig b/.editorconfig index 83b2f2122..f04c13b9f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,8 +5,8 @@ charset = utf-8 # end_of_line = lf indent_size = 2 indent_style = space -# insert_final_newline = false -max_line_length = 100 +insert_final_newline = true +max_line_length = 120 # tab_width = 4 ij_continuation_indent_size = 2 # ij_formatter_off_tag = @formatter:off diff --git a/src/main/kotlin/com/autonomousapps/internal/ConfigurationsToDependenciesTransformer.kt b/src/main/kotlin/com/autonomousapps/internal/ConfigurationsToDependenciesTransformer.kt index d182ed22f..55cef3608 100644 --- a/src/main/kotlin/com/autonomousapps/internal/ConfigurationsToDependenciesTransformer.kt +++ b/src/main/kotlin/com/autonomousapps/internal/ConfigurationsToDependenciesTransformer.kt @@ -15,18 +15,17 @@ internal class ConfigurationsToDependenciesTransformer( companion object { private val DEFAULT_CONFS = listOf( + // Main configurations "api", "implementation", - // Deprecated, removed in Gradle 7 - "compile", - "compileOnly", + "compileOnly", //"compileOnlyApi", // TODO "runtimeOnly", // Test configurations "testRuntimeOnly", "testImplementation", - "testCompileOnly" + "testCompileOnly", ) private val DEFAULT_PROC_CONFS = listOf("kapt", "annotationProcessor") } diff --git a/src/main/kotlin/com/autonomousapps/internal/utils/gradleStrings.kt b/src/main/kotlin/com/autonomousapps/internal/utils/gradleStrings.kt index b2e17c5c2..a3ee5ea6d 100644 --- a/src/main/kotlin/com/autonomousapps/internal/utils/gradleStrings.kt +++ b/src/main/kotlin/com/autonomousapps/internal/utils/gradleStrings.kt @@ -53,7 +53,7 @@ internal fun ComponentIdentifier.resolvedVersion(): String? = when (this) { * [ComponentIdentifier.toIdentifier]. */ internal fun DependencySet.toIdentifiers( - metadataSink: MutableMap + metadataSink: MutableMap = mutableMapOf() ): Set = mapNotNullToSet { it.toIdentifier(metadataSink) } diff --git a/src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt b/src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt index f9e4c038c..e2cdc14b2 100644 --- a/src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt +++ b/src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt @@ -370,25 +370,22 @@ internal class ProjectPlugin(private val project: Project) { * Subproject tasks are registered here. This function is called in a loop, once for each Android * variant or Java source set. */ - private fun Project.analyzeDependencies( - dependencyAnalyzer: DependencyAnalyzer - ) { + private fun Project.analyzeDependencies(dependencyAnalyzer: DependencyAnalyzer) { val flavorName: String? = dependencyAnalyzer.flavorName val variantName = dependencyAnalyzer.variantName val buildType = dependencyAnalyzer.buildType val variantTaskName = dependencyAnalyzer.variantNameCapitalized val outputPaths = OutputPaths(this, variantName) - // Produces a report of all declared dependencies and the configurations on which they are - // declared - val locateDependencies = - tasks.register("locateDependencies$variantTaskName") { - this@register.flavorName.set(flavorName) - this@register.variantName.set(variantName) - this@register.buildType.set(buildType) + // Produces a report of all declared dependencies and the configurations on which they are declared + val locateDependencies = tasks.register("locateDependencies$variantTaskName") { + this@register.flavorName.set(flavorName) + this@register.variantName.set(variantName) + this@register.buildType.set(buildType) + this@register.configurations = this@analyzeDependencies.configurations - output.set(outputPaths.locationsPath) - } + output.set(outputPaths.locationsPath) + } // Produces a report that lists all direct and transitive dependencies, their artifacts val artifactsReportTask = diff --git a/src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt b/src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt index 5e27d9556..95290b18e 100644 --- a/src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt +++ b/src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt @@ -3,26 +3,19 @@ package com.autonomousapps.tasks import com.autonomousapps.TASK_GROUP_DEP_INTERNAL import com.autonomousapps.internal.ConfigurationsToDependenciesTransformer import com.autonomousapps.internal.utils.getAndDelete +import com.autonomousapps.internal.utils.toIdentifiers import com.autonomousapps.internal.utils.toJson import org.gradle.api.DefaultTask +import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* abstract class LocateDependenciesTask : DefaultTask() { init { group = TASK_GROUP_DEP_INTERNAL - description = - "Produces a report of all dependencies and the configurations on which they are declared" - - // This task can never be up to date because we do not yet know a way to model having the - // configurations themselves (not the files they resolve to!) as an input - // TODO May no longer be necessary now that an input is the resolved dependencies - outputs.upToDateWhen { false } + description = "Produces a report of all dependencies and the configurations on which they are declared" } @get:Optional @@ -36,9 +29,15 @@ abstract class LocateDependenciesTask : DefaultTask() { @get:Input abstract val variantName: Property - // For up to date correctness -// @get:Classpath -// abstract val compileClasspathArtifacts: ConfigurableFileCollection + @get:Internal + lateinit var configurations: ConfigurationContainer + + @Input + fun getDeclaredDependencies(): Map> { + return configurations.asMap.map { (name, conf) -> + name to conf.dependencies.toIdentifiers() + }.toMap() + } /* * Outputs @@ -54,7 +53,7 @@ abstract class LocateDependenciesTask : DefaultTask() { flavorName = flavorName.orNull, buildType = buildType.orNull, variantName = variantName.get(), - configurations = project.configurations + configurations = configurations ).locations() outputFile.writeText(locations.toJson())