I want to get the size of each dependencies of my build.gradle in my spring boot project.
I just got a dependencies tree on my intellJ but I want to get the size of the each dependency.
The following task will print out the sizes of the top-level dependencies:
tasks.register("dependenciesWithSizes") {
doLast {
configurations.forEach { eachConfiguration ->
if (eachConfiguration.canBeResolved)
println("Configuration ${eachConfiguration.name}")
eachConfiguration.resolvedConfiguration.firstLevelModuleDependencies.forEach { firstLevelDependency ->
println("t${firstLevelDependency.name}")
firstLevelDependency.moduleArtifacts.forEach { eachArtifact ->
if (eachArtifact.file.exists())
println("ttArtifact name: ${eachArtifact.file.name} of size: ${Files.size(eachArtifact.file.toPath())} bytes")
else
println("ttArtifact name: ${eachArtifact.file.name} (can't find file)")
}
}
}
}
}
If you want to print out the sizes of the dependencies of those dependencies (so-called transitive dependencies) you can access them via the children
property of firstLevelDependency
.