Skip to content

Commit 92910c8

Browse files
LocateDependenciesTask can be up to date.
1 parent 34f08f6 commit 92910c8

File tree

5 files changed

+29
-34
lines changed

5 files changed

+29
-34
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ charset = utf-8
55
# end_of_line = lf
66
indent_size = 2
77
indent_style = space
8-
# insert_final_newline = false
9-
max_line_length = 100
8+
insert_final_newline = true
9+
max_line_length = 120
1010
# tab_width = 4
1111
ij_continuation_indent_size = 2
1212
# ij_formatter_off_tag = @formatter:off

src/main/kotlin/com/autonomousapps/internal/ConfigurationsToDependenciesTransformer.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ internal class ConfigurationsToDependenciesTransformer(
1515

1616
companion object {
1717
private val DEFAULT_CONFS = listOf(
18+
// Main configurations
1819
"api",
1920
"implementation",
20-
// Deprecated, removed in Gradle 7
21-
"compile",
22-
"compileOnly",
21+
"compileOnly",
2322
//"compileOnlyApi", // TODO
2423
"runtimeOnly",
2524

2625
// Test configurations
2726
"testRuntimeOnly",
2827
"testImplementation",
29-
"testCompileOnly"
28+
"testCompileOnly",
3029
)
3130
private val DEFAULT_PROC_CONFS = listOf("kapt", "annotationProcessor")
3231
}

src/main/kotlin/com/autonomousapps/internal/utils/gradleStrings.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal fun ComponentIdentifier.resolvedVersion(): String? = when (this) {
5353
* [ComponentIdentifier.toIdentifier].
5454
*/
5555
internal fun DependencySet.toIdentifiers(
56-
metadataSink: MutableMap<String, Boolean>
56+
metadataSink: MutableMap<String, Boolean> = mutableMapOf()
5757
): Set<String> = mapNotNullToSet {
5858
it.toIdentifier(metadataSink)
5959
}

src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt

+9-12
Original file line numberDiff line numberDiff line change
@@ -370,25 +370,22 @@ internal class ProjectPlugin(private val project: Project) {
370370
* Subproject tasks are registered here. This function is called in a loop, once for each Android
371371
* variant or Java source set.
372372
*/
373-
private fun <T : ClassAnalysisTask> Project.analyzeDependencies(
374-
dependencyAnalyzer: DependencyAnalyzer<T>
375-
) {
373+
private fun <T : ClassAnalysisTask> Project.analyzeDependencies(dependencyAnalyzer: DependencyAnalyzer<T>) {
376374
val flavorName: String? = dependencyAnalyzer.flavorName
377375
val variantName = dependencyAnalyzer.variantName
378376
val buildType = dependencyAnalyzer.buildType
379377
val variantTaskName = dependencyAnalyzer.variantNameCapitalized
380378
val outputPaths = OutputPaths(this, variantName)
381379

382-
// Produces a report of all declared dependencies and the configurations on which they are
383-
// declared
384-
val locateDependencies =
385-
tasks.register<LocateDependenciesTask>("locateDependencies$variantTaskName") {
386-
this@register.flavorName.set(flavorName)
387-
this@register.variantName.set(variantName)
388-
this@register.buildType.set(buildType)
380+
// Produces a report of all declared dependencies and the configurations on which they are declared
381+
val locateDependencies = tasks.register<LocateDependenciesTask>("locateDependencies$variantTaskName") {
382+
this@register.flavorName.set(flavorName)
383+
this@register.variantName.set(variantName)
384+
this@register.buildType.set(buildType)
385+
this@register.configurations = this@analyzeDependencies.configurations
389386

390-
output.set(outputPaths.locationsPath)
391-
}
387+
output.set(outputPaths.locationsPath)
388+
}
392389

393390
// Produces a report that lists all direct and transitive dependencies, their artifacts
394391
val artifactsReportTask =

src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@ package com.autonomousapps.tasks
33
import com.autonomousapps.TASK_GROUP_DEP_INTERNAL
44
import com.autonomousapps.internal.ConfigurationsToDependenciesTransformer
55
import com.autonomousapps.internal.utils.getAndDelete
6+
import com.autonomousapps.internal.utils.toIdentifiers
67
import com.autonomousapps.internal.utils.toJson
78
import org.gradle.api.DefaultTask
9+
import org.gradle.api.artifacts.ConfigurationContainer
810
import org.gradle.api.file.RegularFileProperty
911
import org.gradle.api.provider.Property
10-
import org.gradle.api.tasks.Input
11-
import org.gradle.api.tasks.Optional
12-
import org.gradle.api.tasks.OutputFile
13-
import org.gradle.api.tasks.TaskAction
12+
import org.gradle.api.tasks.*
1413

1514
abstract class LocateDependenciesTask : DefaultTask() {
1615

1716
init {
1817
group = TASK_GROUP_DEP_INTERNAL
19-
description =
20-
"Produces a report of all dependencies and the configurations on which they are declared"
21-
22-
// This task can never be up to date because we do not yet know a way to model having the
23-
// configurations themselves (not the files they resolve to!) as an input
24-
// TODO May no longer be necessary now that an input is the resolved dependencies
25-
outputs.upToDateWhen { false }
18+
description = "Produces a report of all dependencies and the configurations on which they are declared"
2619
}
2720

2821
@get:Optional
@@ -36,9 +29,15 @@ abstract class LocateDependenciesTask : DefaultTask() {
3629
@get:Input
3730
abstract val variantName: Property<String>
3831

39-
// For up to date correctness
40-
// @get:Classpath
41-
// abstract val compileClasspathArtifacts: ConfigurableFileCollection
32+
@get:Internal
33+
lateinit var configurations: ConfigurationContainer
34+
35+
@Input
36+
fun getDeclaredDependencies(): Map<String, Set<String>> {
37+
return configurations.asMap.map { (name, conf) ->
38+
name to conf.dependencies.toIdentifiers()
39+
}.toMap()
40+
}
4241

4342
/*
4443
* Outputs
@@ -54,7 +53,7 @@ abstract class LocateDependenciesTask : DefaultTask() {
5453
flavorName = flavorName.orNull,
5554
buildType = buildType.orNull,
5655
variantName = variantName.get(),
57-
configurations = project.configurations
56+
configurations = configurations
5857
).locations()
5958

6059
outputFile.writeText(locations.toJson())

0 commit comments

Comments
 (0)