-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathlist-dependencies.gradle
117 lines (107 loc) · 4.51 KB
/
list-dependencies.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// List Sub-Modules (or) Projects from the given Android App/Library
task printSubModuleNames {
doLast {
subprojects.each {
println it.name
}
}
}
// List All the dependencies from the given Android App/Library
task printSubProjectDependencies {
doLast {
subprojects.each { subproject ->
println("Dependencies for ${subproject.name}:")
subproject.configurations.each { config ->
println("Configuration: ${config.name}")
config.dependencies.forEach { dependency ->
println(" - ${dependency.group}:${dependency.name}:${dependency.version}")
}
}
println("\n")
}
}
}
// Define the group you are interested in
def interestedGroup = 'com.clover'
allprojects {
// Task to get direct and transitive dependencies for all groups
task getAllDependencies {
doLast {
// Make a copy of the configurations collection
def configs = configurations.toList()
// Iterate over the copied configurations
configs.each { config ->
try {
// Print the dependency tree for each configuration
println "Configuration: ${config.name}"
config.resolve()
println config.incoming.resolutionResult.allDependencies.collect { it_test ->
"${it_test.from.moduleVersion}|${it_test.requested}|[${it_test.constraint ? 'constraint' : 'direct'}]"
}.join('\n')
} catch (Exception e) {
// Catch cases where a configuration cannot be resolved
println "Could not resolve configuration: ${config.name}"
}
}
}
}
// Task to get direct and transitive dependencies for com.clover group
task getInternalDependencies {
doLast {
def filteredDependencies = [:] as TreeMap // Use TreeMap to sort groups
// Make a copy of the configurations collection
def configs = configurations.toList()
// Iterate over the copied configurations
configs.each { config ->
try {
config.resolvedConfiguration.lenientConfiguration.allModuleDependencies.each { dependency ->
// Check if this dependency is from the group we're interested in
if (dependency.moduleGroup =~ interestedGroup) {
// Initialize a set for the group if it doesn't exist
filteredDependencies.putIfAbsent(dependency.moduleGroup, [] as TreeSet)
// Add the module name and version
// filteredDependencies[dependency.moduleGroup].add("${dependency.moduleName}")
filteredDependencies[dependency.moduleGroup].add("${dependency.moduleGroup}:${dependency.moduleName}:${dependency.moduleVersion}")
}
}
} catch (Exception ignored) {
// Exceptions for unresolvable configurations are ignored
}
}
// Print filtered dependencies
if (filteredDependencies.isEmpty()) {
println "No dependencies found matching criteria."
} else {
filteredDependencies.each { group, dependencies ->
// println "Dependencies for group: $group"
dependencies.each {
println "$it"
}
}
}
}
}
}
task listSpecificGroupDependencies {
doLast {
def group = 'com.clover'
def uniqueDependencies = []
subprojects.each { subproject ->
// println("Dependencies for ${subproject.name}:")
subproject.configurations.each { config ->
// println("Configuration: ${config.name}")
config.dependencies.forEach { dependency ->
if (dependency.group =~ group) {
String depString = "${dependency.group}:${dependency.name}:${dependency.version}"
if (!uniqueDependencies.contains(depString)) {
uniqueDependencies.add(depString)
}
}
}
}
}
uniqueDependencies.sort().each {
println it
}
}
}