Created
October 13, 2021 17:40
-
-
Save ghale/6d67fd32b28242536590ee4bef7b711f to your computer and use it in GitHub Desktop.
Finding values of file properties for kotlin compile tasks
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
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