Gradle inputs and outputs

I am studying Gradle and trying to understand how input and output files determine if a task is relevant.

This task is never updated, even if the assembly file does not change.

task printFoo() { inputs.file(getBuildFile()) doLast { println 'foo' } } 

This task is always relevant, even if the assembly file is modified.

  task printFoo() { outputs.file(getBuildFile()) doLast { println 'foo' } } 

I expected both examples to consider the task obsolete only when the assembly file changes and is updated otherwise. What am I missing?

+6
source share
1 answer

Gradle needs timestamps for inputs and outputs to determine if task results are out of date.

In the first case, you do not have output timestamps because you have no output. Gradle cannot determine if your exits match because they don't know them. Therefore, he considers your exits always outdated. From the documentation: "A task without specific outputs will never be considered relevant." ( https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks )

In the second case, Gradle should do what you expect: look at the output of the task that was deprecated when the build file was modified. From the documentation: "A task with certain results will be considered relevant if these results do not change since the previous build." This may be a mistake, but I think it is because you are using the assembly file as output. Have you tried it with another file?

+5
source

Source: https://habr.com/ru/post/988794/


All Articles