-
-
Save anthonymonori/3ac1f35e1a79d63aee3a5eb2f0315502 to your computer and use it in GitHub Desktop.
Capture task classpath fingerprints with Gradle Kotlin DSL
This file contains hidden or 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
// Add into root project, make sure you have Gradle Enterprise plugin | |
val buildScanApi = project.extensions.findByName("buildScan") as BuildScanExtension | |
subprojects { | |
// If you want to limit it to certain module(s), wrap it with: if (name == "module-name") { } | |
val fingerprinter = serviceOf<org.gradle.internal.fingerprint.classpath.ClasspathFingerprinter>() | |
tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinCompile::class.java).configureEach task@{ | |
doFirst { | |
var classLoader: ClassLoader = [email protected] | |
while (classLoader is java.net.URLClassLoader) { | |
val fingerprints = mutableSetOf<Array<String>>() | |
val allFiles = mutableSetOf<File>() | |
classLoader.urLs.forEach { | |
fingerprints.add( | |
arrayOf( | |
"${[email protected]}:${file(it.file).name}", | |
"${fingerprinter.fingerprint(files(it.file)).hash}" | |
) | |
) | |
allFiles.add(file(it.file)) | |
} | |
fingerprints.forEach { fingerprint -> | |
buildScanApi.value(fingerprint[0], fingerprint[1]) | |
} | |
buildScanApi.value( | |
"${[email protected]}:classpath", | |
allFiles.joinToString("\n") | |
) | |
classLoader = classLoader.parent | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment