-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only resolve external dependencies. More performant.
- Loading branch information
1 parent
824d18a
commit 074b0a3
Showing
8 changed files
with
113 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/com/autonomousapps/tasks/ResolveExternalDependenciesTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.autonomousapps.tasks | ||
|
||
import com.autonomousapps.TASK_GROUP_DEP_INTERNAL | ||
import com.autonomousapps.internal.GradleVersions | ||
import com.autonomousapps.internal.externalArtifactsFor | ||
import com.autonomousapps.internal.graph.GraphViewBuilder | ||
import com.autonomousapps.internal.utils.getAndDelete | ||
import com.autonomousapps.model.ModuleCoordinates | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.* | ||
|
||
@Suppress("UnstableApiUsage") // Guava graphs | ||
@CacheableTask | ||
abstract class ResolveExternalDependenciesTask : DefaultTask() { | ||
|
||
init { | ||
group = TASK_GROUP_DEP_INTERNAL | ||
description = "Resolves external dependencies for single variant." | ||
|
||
if (GradleVersions.isAtLeastGradle74) { | ||
@Suppress("LeakingThis") | ||
notCompatibleWithConfigurationCache("Cannot serialize Configurations") | ||
} | ||
} | ||
|
||
@Transient | ||
private lateinit var compileClasspath: Configuration | ||
|
||
@Transient | ||
private lateinit var runtimeClasspath: Configuration | ||
|
||
@get:PathSensitive(PathSensitivity.NAME_ONLY) | ||
@get:InputFiles | ||
abstract val compileFiles: ConfigurableFileCollection | ||
|
||
@get:PathSensitive(PathSensitivity.NAME_ONLY) | ||
@get:InputFiles | ||
abstract val runtimeFiles: ConfigurableFileCollection | ||
|
||
/** Output in json format for compile classpath graph. */ | ||
@get:OutputFile | ||
abstract val output: RegularFileProperty | ||
|
||
internal fun configureTask( | ||
project: Project, | ||
compileClasspath: Configuration, | ||
runtimeClasspath: Configuration, | ||
jarAttr: String | ||
) { | ||
this.compileClasspath = compileClasspath | ||
this.runtimeClasspath = runtimeClasspath | ||
compileFiles.setFrom(project.provider { compileClasspath.externalArtifactsFor(jarAttr).artifactFiles }) | ||
runtimeFiles.setFrom(project.provider { runtimeClasspath.externalArtifactsFor(jarAttr).artifactFiles }) | ||
} | ||
|
||
@TaskAction fun action() { | ||
val output = output.getAndDelete() | ||
|
||
val compileGraph = GraphViewBuilder(compileClasspath).graph | ||
val runtimeGraph = GraphViewBuilder(runtimeClasspath).graph | ||
|
||
val dependencies = compileGraph.nodes().asSequence().plus(runtimeGraph.nodes().asSequence()) | ||
.filterIsInstance<ModuleCoordinates>() | ||
.toSortedSet() | ||
|
||
output.writeText(dependencies.joinToString(separator = "\n") { it.gav() }) | ||
} | ||
} |