Skip to content

Instantly share code, notes, and snippets.

@jprinet
Created July 20, 2022 08:24
Show Gist options
  • Save jprinet/dafe3b07f721e5f0ff9032b08d92c9a8 to your computer and use it in GitHub Desktop.
Save jprinet/dafe3b07f721e5f0ff9032b08d92c9a8 to your computer and use it in GitHub Desktop.
Capture classpath entries with their size
import java.nio.file.Files
tasks.withType(JavaCompile) {
doLast {
def sizes = it.classpath.collect {
if (it.isFile()) {
return new FileSize(Files.size(it.toPath())/(1024*1024), "F ${it}")
} else {
return new FileSize(0, "D ${it}")
}
}.sort().reverse()
buildScan.value "${project.name}.compileClasspath", sizes.join("\n")
}
}
class FileSize implements Comparable {
float size
String description
public FileSize(float size, String description) {
this.size = size
this.description = description
}
int compareTo(Object other) {
return size.compareTo(other.size)
}
String toString() {
return "${String.format('%.2f', size)}mb ${description}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment