Gradle task inputs and outputs¶
In Gradle, tasks can define their inputs and outputs explicitly.^[600-developer-gradle-gradle-build.md] This mechanism allows Gradle to track the data and resources a task consumes and produces, which is essential for the build system's optimization logic.
TaskInputs and TaskOutputs¶
The specific interfaces for managing these elements are TaskInputs and TaskOutputs.^[600-developer-gradle-gradle-build.md] By declaring inputs and outputs, developers inform Gradle about the state dependencies of a task.
Build Optimization¶
The primary purpose of defining inputs and outputs is to support UP-TO-DATE checking.^[600-developer-gradle-gradle-build.md] Before executing a task, Gradle checks if the input files or properties have changed since the last successful execution. If the inputs are identical and the outputs already exist, Gradle considers the task "up-to-date" and skips execution (marked as UP-TO-DATE in the console).^[600-developer-gradle-gradle-build.md] This behavior significantly reduces build times for large projects by avoiding redundant work.
Related Concepts¶
- Gradle
- [[Gradle task creation]]
- [[Build lifecycle]]
Sources¶
600-developer-gradle-gradle-build.md