hello, I'm writing some custom tasks and would lik...
# gradle
d
hello, I'm writing some custom tasks and would like to use output file from one task as an input to another -> resolved
Copy code
open class MyCustomTask1 : DefaultTask() {

    @Input
    @Option(option = "outputFileName", description = "output file name")
    val outputFileName: Property<String> = project.objects.property(String::class.java)

    @OutputFile
    val outputFile: Provider<RegularFile> = outputFileName.flatMap { name -> project.layout.buildDirectory.file(name) }

    // actual task code omitted for clarity
}

open class MyCustomTask2 : DefaultTask() {

    @Input
    @Optional
    @Option(option = "inputFileName", description = "input file name")
    val inputFileName: Property<String> = project.objects.property(String::class.java)

    @Input
    @Optional
    val inputFile: RegularFileProperty = project.objects.fileProperty()

    // skipping code
}
While individual tasks worked fine I'm trying to configure
task2
to use
task1
output, e.g. in
build.gradle.kts
Copy code
val firstTask by tasks.getting(MyCustomTask1::class) {
  // configuration
}
val secondTask by tasks.getting(MyCustomTask2::class) {
    inputFile.set(firstTask.outputFile)

    dependsOn("firstTask")
}
unfortunately when run I'm hitting
Copy code
Unable to store input properties for task .... Property 'inputFile' with value '/valid/path/to/task1/outputFile' cannot be serialized.
Any ideas?
problem was with
task2
using
@Input
on
RegularFileProperty
it works when I updated it to
@InputFile
m
I might be wrong, but what happened when you prioritize
dependsOn
first then running your
inputFile.set
? does your
outputFile
exist?
d
It correctly run task1 and generated its output
But faile don task2 with the serialization error
Fix was to use @InputFile instead of @Input
👍 1
m
nice, thanks for the answer