DevOps / Gradle8 Interview Questions
Why is task input/output declaration important for incremental builds?
Gradle's whole incremental-build model — skipping tasks that don't need to rerun — only works if a task accurately declares everything that could affect its result as an input, and everything it produces as an output. If a task silently reads a file, property, or dependency that isn't declared, Gradle has no way to know a change to that thing should invalidate the task's up-to-date status.
tasks.register('generateConfig') { def env = providers.gradleProperty('deploy.env') inputs.property('environment', env) outputs.file('build/config.properties') doLast { file('build/config.properties').text = "env=${env.get()}" } }
Under-declaring inputs causes false up-to-date results — stale output silently reused when it shouldn't be, which is a much harder bug to notice than a task simply running unnecessarily. Over-declaring (marking something as an input that doesn't actually affect the result) causes the opposite problem: unnecessary reruns that waste build time even though nothing meaningful changed. Getting this declaration right is what makes a custom task actually benefit from Gradle's caching model instead of just adding overhead without the payoff.
More Related questions...
