Add gradle task to compute total size of dependencies
@@ -134,3 +134,48 @@ jacocoTestReport {
}
+//
+// Task to compute total size of dependencies:
+// gradle depsize
+// Taken from:
+// - https://gist.github.com/medvedev/968119d7786966d9ed4442ae17aca279
+// - https://stackoverflow.com/questions/22175847/maven-gradle-way-to-calculate-the-total-size-of-a-dependency-with-all-its-transi
+//
+tasks.register("depsize") {
+ description = 'Prints dependencies for "default" configuration'
+ doLast() {
+ listConfigurationDependencies(configurations.default)
+ }
+}
+
+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 formatStr = "%,10.2f"
+
+ def size = configuration.collect { it.length() / (1024 * 1024) }.sum()
+
+ def out = new StringBuffer()
+ out << "\nConfiguration name: \"${configuration.name}\"\n"
+ if (size) {
+ out << 'Total dependencies size:'.padRight(65)
+ out << "${String.format(formatStr, size)} Mb\n\n"
+
+ configuration.sort { -it.length() }
+ .each {
+ out << "${it.name}".padRight(65)
+ out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
+ }
+ } else {
+ out << 'No dependencies found';
+ }
+ println(out)
+}
+
