I have had problems with that the Exec task in gradle have problems with the up-to-date check if the output files is captured from standardOutput.
I have tried to simplify the example as much as possible:
task printToOutputFile(type: Exec) {
inputs.file file("file1") // not relevant for this example
outputs.file file("file2")
commandLine = ["echo", "1234"]
standardOutput = new FileOutputStream("file2")
}
When rerunning this task I expect it to be UP-TO-DATE but it is not.
How can I make the UP-TO-DATE check work when using the standardOutput as outputs?
What I have tried:
Closing and/or Flushing the stream in an doLast block.
the problem is, that the line
changes the lastModified attribute of file2. To get the up-to-date check working, you have to move this assignment to the execution phase. You can do this by putting this assignment in a doFirst block. The following snippet should do the trick:
cheers,
René