Skip to content

Instantly share code, notes, and snippets.

@martinda
Last active March 3, 2024 02:38
Show Gist options
  • Save martinda/56638e34fc8e316d32389a3568f6e183 to your computer and use it in GitHub Desktop.
Save martinda/56638e34fc8e316d32389a3568f6e183 to your computer and use it in GitHub Desktop.
List artifacts of dependencies using Gradle
// build.gradle
void printArtifacts(Set<ResolvedArtifact> resolvedArtifacts, int level) {
println(" "*level + "Artifacts:")
for (def resolvedArtifact in resolvedArtifacts) {
println(" " * level + resolvedArtifact)
}
}
void printDependencies(ResolvedDependency parent, Set<ResolvedDependency> resolvedDependencies, int level) {
if (resolvedDependencies.size() == 0) return
println(" "*level + "Resolved dependencies:")
resolvedDependencies.each {
println(" "*level + it)
printArtifacts(it.getArtifacts(parent), level + 4)
printDependencies(it, it.getChildren(), level + 4)
}
}
void printDependencies(Set<ResolvedDependency> resolvedDependencies, int level) {
if (resolvedDependencies.size() == 0) return
println(" "*level + "Resolved dependencies:")
resolvedDependencies.each {
println(" "*level + it)
printDependencies(it, it.getChildren(), level + 4)
}
}
void printResolvedConfiguration(ResolvedConfiguration rc) {
printDependencies(rc.getFirstLevelModuleDependencies(), 4)
}
task printDeps {
doLast {
for (def rd in configurations) {
println(rd)
if (!rd.isCanBeResolved()) continue
def rc = rd.getResolvedConfiguration()
printResolvedConfiguration(rc)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment