Last active
July 21, 2023 15:43
Revisions
-
arunkumar9t2 revised this gist
May 25, 2022 . 1 changed file with 18 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -50,10 +50,19 @@ abstract class DependantModulesTask : DefaultTask() { } val projectToFind = rootProject.project(projectPath) val dependants = Graphs.reachableNodes(buildGraph.asGraph(), projectToFind) logger.quiet(buildString { appendLine() append("${projectToFind.path}'s dependants :") appendLine() append( dependants .filter { it != projectToFind } .joinToString(separator = "\n") { it.path } ) }) logger.quiet("----------\n") val subgraph = Graphs.inducedSubgraph(buildGraph, dependants) @@ -64,7 +73,13 @@ abstract class DependantModulesTask : DefaultTask() { .edgeValue(endpointPair) .map { it.name } .orElse("") val sourceProject = endpointPair.nodeV().path val dependencyProject = endpointPair.nodeU().path logger.quiet( """|$sourceProject | $configuration(project("$dependencyProject"))""" .trimMargin() ) } } } -
arunkumar9t2 created this gist
May 24, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ import com.google.common.graph.Graphs import com.google.common.graph.MutableValueGraph import com.google.common.graph.ValueGraphBuilder import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.options.Option abstract class DependantModulesTask : DefaultTask() { @Option( option = "project-path", description = "The project path to find dependencies for" ) @Input lateinit var projectPath: String @TaskAction fun action() { val rootProject = project.rootProject val buildGraph: MutableValueGraph<Project, Configuration> = ValueGraphBuilder.directed() .allowsSelfLoops(false) .expectedNodeCount(rootProject.subprojects.size) .build() rootProject.subprojects.forEach { sourceProject -> buildGraph.addNode(sourceProject) sourceProject .configurations .flatMap { configuration -> configuration .dependencies .filterIsInstance<ProjectDependency>() .map { projectDependency -> configuration to projectDependency } }.forEach { (configuration, projectDependency) -> if (sourceProject != projectDependency.dependencyProject) { // Invert the order since we are only interested in reverse dependencies buildGraph.putEdgeValue( projectDependency.dependencyProject, sourceProject, configuration ) } } } val projectToFind = rootProject.project(projectPath) val dependants = Graphs.reachableNodes(buildGraph.asGraph(), projectToFind) logger.quiet("\n${projectToFind.path}'s dependants : \n${dependants.joinToString(separator = "\n") { it.path }}") logger.quiet("----------\n") val subgraph = Graphs.inducedSubgraph(buildGraph, dependants) subgraph .edges() .forEach { endpointPair -> val configuration = buildGraph .edgeValue(endpointPair) .map { it.name } .orElse("") logger.quiet("${endpointPair.nodeV().path} ---$configuration---> ${endpointPair.nodeU().path}") } } }