Skip to content

Instantly share code, notes, and snippets.

@ghale
Created October 13, 2021 17:40
Show Gist options
  • Save ghale/6d67fd32b28242536590ee4bef7b711f to your computer and use it in GitHub Desktop.
Save ghale/6d67fd32b28242536590ee4bef7b711f to your computer and use it in GitHub Desktop.
Finding values of file properties for kotlin compile tasks
subprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompileWithWorkers).configureEach { task ->
doFirst {
task.inputs.visitRegisteredProperties(new PropertyVisitor(task))
}
}
}
import org.gradle.api.internal.tasks.properties.*
class PropertyVisitor extends PropertyVisitor.Adapter {
def task
def buildScan
PropertyVisitor(task) {
this.task = task
this.buildScan = task.project.rootProject.buildScan
}
void visitInputFileProperty(
String propertyName,
boolean optional,
boolean skipWhenEmpty,
org.gradle.internal.fingerprint.DirectorySensitivity directorySensitivity,
org.gradle.internal.fingerprint.LineEndingSensitivity lineEndingSensitivity,
boolean incremental,
Class<? extends org.gradle.api.tasks.FileNormalizer> fileNormalizer,
PropertyValue value,
InputFilePropertyType filePropertyType
) {
def v = value.call()
if (v instanceof FileCollection) {
v = v.files.join("\n")
} else if (v instanceof List) {
v = v.join("\n")
}
buildScan.value "${task.path}.${propertyName}", v.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment