[GRADLE-2390] Task input for simple property never UP-TO-DATE Created: 14/Jul/12  Updated: 01/Jun/16  Resolved: 01/Jun/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Kelly Robinson Assignee: Unassigned
Resolution: Not A Bug Votes: 0


 Description   

Taking this example from Mr. Haki's blog, if you don't have the file as an output to the task, it will run every time. The value set for 'version' is never considered UP-TO-DATE, although it will be detected if it has changed.

version = '1.0'
outputFile = file("$buildDir/version.txt")

task generateVersionFile << {
    if (!outputFile.isFile()) {
        outputFile.parentFile.mkdirs()
        outputFile.createNewFile()
    }
    outputFile.write "Version: $version"
}

generateVersionFile.inputs.property "version", version
//without the outputFile the task will run every time
//generateVersionFile.outputs.files outputFile

task showContents << {
    println outputFile.text
}
showContents.dependsOn generateVersionFile



 Comments   
Comment by Lóránt Pintér [ 01/Jun/16 ]

This is by design. A task is up-to-date when both its inputs and outputs match that of the previous execution. A task must have outputs declared (though it doesn't necessarily need inputs) for Gradle to be able to compare its state to the previous execution.

Generated at Wed Jun 30 12:20:36 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.