Created
July 20, 2022 08:24
-
-
Save jprinet/dafe3b07f721e5f0ff9032b08d92c9a8 to your computer and use it in GitHub Desktop.
Capture classpath entries with their size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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