Skip to content

Instantly share code, notes, and snippets.

@jprinet
Last active February 9, 2023 10:21
Show Gist options
  • Save jprinet/e3ae69fc50f2ef5ef2b3690d4cdb0882 to your computer and use it in GitHub Desktop.
Save jprinet/e3ae69fc50f2ef5ef2b3690d4cdb0882 to your computer and use it in GitHub Desktop.
Capture collection fingerprints
val libraryFingerprint by tasks.registering(LibraryFingerprint::class) {
inputFiles.from(sourceSets["main"].output)
}
tasks.named("build").configure {
dependsOn(libraryFingerprint)
}
abstract class LibraryFingerprint : DefaultTask() {
@get:Inject
abstract val fingerprinter: org.gradle.internal.fingerprint.classpath.ClasspathFingerprinter
@get:Inject
abstract val objectFactory: ObjectFactory
@get:InputFiles
@get:Classpath
abstract val inputFiles: ConfigurableFileCollection
@TaskAction
fun execute() {
inputFiles.asFileTree.forEach { file ->
println("${file.name} = ${fingerprinter.fingerprint(objectFactory.fileCollection().from(file)).hash}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment