Zak Taccardi
10/30/2024, 7:15 PMKspTask Gradle task in a consumer task?
I'm seeing:
kspTask.outputs.files
return an empty FileCollection. Even though
build/generated/ksp/test/resources is non-empty.
If I re-execute the task (and Gradle does another configuration phase pass), kspTask.outputs.files is correctly non-empty and this works as expected.Vampire
10/30/2024, 10:10 PMKspTask anywhere) for example has an @OutputDirectory property, the actual output files can hardly be known before the task executed. "works as expected" is most probably also not correct, as you most probably get the files of the last ran and not the files that will be there after the next run.Zak Taccardi
10/30/2024, 10:20 PMinterface KspTask implemented by `KspTaskJvm`: https://github.com/google/ksp/blob/d98bc9c3f8b8b14f3d62543d64707a49f8514c73/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt#L184-L206
note: I’m referring to kspTask.outputs.files being empty when it is input to a downstream Task, such as:
abstract class ListFilesTask : DefaultTask() {
@get:InputFiles
abstract val input: ConfigurableFileCollection
// ..
}Zak Taccardi
10/30/2024, 10:23 PMkspTask.outputs refers to: https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api/-task/get-outputs.htmlZak Taccardi
10/30/2024, 10:25 PM—no-configuration-cache it seems to work on our CI server (our CI server is ephemeral and every build is a completely clean build, though it leverages a remote build cache)Zak Taccardi
10/30/2024, 10:26 PMobjects.fileCollection() and have it .builtBy(kspTask) - but I’m not sure why kspTask.outputs doesn’t workVampire
10/30/2024, 10:27 PMoutputs.files?
Just give the task itself to the downstream taskVampire
10/30/2024, 10:27 PMVampire
10/30/2024, 10:28 PMoutputs.files probably does not carry the task dependencyZak Taccardi
10/30/2024, 10:36 PMjust give the task itself to the downstream taskwhat do you mean? My downstream task has a:
@get:InputFiles
abstract val yamlFilesToMerge: SetProperty<FileSystemLocation>
as inputZak Taccardi
10/30/2024, 10:40 PMit does with:probably does not carry the task dependencyoutputs.files
task.outputs
.files
.asFileTree
.filter { it.isYamlFile() }
.elements
which returns a Provider<Set<FileSystemLocation>>Vampire
10/30/2024, 10:47 PMit.isYamlFile() do?Zak Taccardi
10/30/2024, 11:01 PMfile.endsWith(".yaml") check.
But it doesn't matter, bc the task.outputs.files is empty anywayVampire
10/30/2024, 11:39 PMval foo by tasks.registering {
val output = layout.buildDirectory.file("foo")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
output.get().asFile.writeText("foo")
}
}
abstract class Bar : DefaultTask() {
@get:InputFiles
abstract val yamlFilesToMerge: SetProperty<FileSystemLocation>
@TaskAction
fun bar() {
yamlFilesToMerge.get().forEach { }
}
}
val bar by tasks.registering(Bar::class) {
outputs.upToDateWhen { false }
yamlFilesToMerge = foo.get().outputs.files.asFileTree.filter { println("FOO"); it.name == "foo" }.elements
}Vampire
10/30/2024, 11:42 PMFOO is only printed at execution time of bar after foo already executed and the file is there, also with clean worktree and CC used.Zak Taccardi
10/31/2024, 12:45 AMZak Taccardi
10/31/2024, 3:09 AMKspTaskJvm.destinationDirectory and add a new intermediary task that converted the Directory (@InputDirectory) into a RegularFile (@OutputFile)
Not sure why I had to do that, but it is what it is!TrevJonez
11/05/2024, 9:14 PMZak Taccardi
11/05/2024, 11:38 PMVampire
11/06/2024, 7:54 AM