/* Tested with Gradle gradle-6.6.1-all.zip and gradle plugin 4.0.2 */
allprojects {
repositories {
afterEvaluate {
tasks.register("depsize-all-configurations") {
description = 'Prints dependencies for all available configurations'
doLast() {
configurations
.findAll { it.isCanBeResolved() }
.each { listConfigurationDependencies(it) }
}
}
}
}
//...
def listConfigurationDependencies(Configuration configuration) {
def configurationWhichSaveToMarkdown = "_classStructurekaptDebugKotlin"
def formatStr = "%,10.2f"
def size = configuration.collect { it.length() / (1024 * 1024) }.sum()
def Date now = new Date()
def out = new StringBuffer()
out << "\n Date :${now.getDateString()} \n Configuration name: \"${configuration.name}\"\n"
if (size) {
out << '\nTotal dependencies size:'.padRight(65)
out << "${String.format(formatStr, size)} Mb\n\n"
out << '| file | size |\n'
out << '|----------|------:|\n'
configuration.sort { -it.length() }
.each {
String name = it.name
if(name == "classes.jar"){//this name is not clear, I have to print its parent dir name.
File file = it.getAbsoluteFile()
while (file.parentFile!=null){
if (file.name=="build"){
file = file.parentFile
name = file.getName() +"/build/.../" + name
break
}
file = file.parentFile
}
}
out << "| ${name} ".padRight(65)
out << "| ${String.format(formatStr, (it.length() / 1024))} kb |\n"
}
} else {
out << 'No dependencies found';
}
println(out)
if (configuration.name == configurationWhichSaveToMarkdown) {
new File(projectDir, "all_libs.md").text = out
}
}
-
-
Save BruceWind/0bf231688c77fafef0b7e4e42f940084 to your computer and use it in GitHub Desktop.
Gradle task that prints total dependencies size and (dependency+(size in kb)) list sorted by size desc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I modified the original author's code, and some information will be saved in all_libs.md as markdown form for analyzing easily.
Hope you enjoy it.