Is there a way to ask gradle if anything is not up-to-date and would need to be built (without actually building it then)?
Gradle will determine if a task is up to date by checking the inputs and outputs. For example, your compile task input is the source code. If the source code hasn't changed since the last compile, then it will check the output to make sure you haven't blown away your class files generated by the compiler.
To do that, just pick the Gradle Remote Debug configuration and then click the Debug icon on the project to be debugged. For more info, you can read the Gradle documentation. Follow us for more productivity tools & ideas for Android, Kotlin & Gradle projects.
Incremental build If neither a task's inputs nor its outputs have changed since the last time it was run, Gradle will not run it again. Incremental build is the name Gradle gives to this feature of checking inputs and outputs to determine whether a task needs to run again or not.
This is not possible. The up-to-date check happens in the execution phase, just before the doFirst
is run. It is calculated and this value is not stored. Moreover, the up-to-date check might depend on the previous task(s) outputs. Therefore to resolve a task's up-to-date status you need to execute all it's dependencies (dependsOn
tasks). Therefore what you are asking would theoretically work only for the first task that is not up-to-date.
To see how the lifecycle works, here's a simple example:
task hello {
println "CONFIG1"
outputs.upToDateWhen {
println "UPTODATE"
return false
}
println "CONFIG2"
doFirst {
println "DOFIRST"
}
doLast {
println "DOLAST"
}
}
If you execute this with the --debug
flag, you will see this first:
08:05:17.294 [DEBUG] [org.gradle.model.internal.registry.DefaultModelRegistry] Project : - Registering model element 'tasks.hello' (hidden = false)
08:05:17.302 [QUIET] [system.out] CONFIG1
08:05:17.329 [QUIET] [system.out] CONFIG2
08:05:17.333 [DEBUG] [org.gradle.configuration.project.BuildScriptProcessor] Timing: Running the build script took 0.764 secs
The config phase sets up the up-to-date check. Then Gradle calculates the graph of tasks:
08:16:26.212 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskGraphExecuter] Timing: Creating the DAG took 0.007 secs
And only then it executes the tasks:
08:05:17.430 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :hello (Thread[main,5,main]) started.
08:05:17.431 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :hello
08:05:17.432 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':hello'
08:05:17.461 [QUIET] [system.out] UPTODATE
08:05:17.465 [INFO] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Putting task artifact state for task ':hello' into context took 0.032 secs.
08:05:17.465 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Determining if task ':hello' is up-to-date
08:05:17.465 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':hello' (up-to-date check took 0.0 secs) due to:
Task.upToDateWhen is false.
08:05:17.466 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':hello'.
08:05:17.467 [QUIET] [system.out] DOFIRST
08:05:17.467 [QUIET] [system.out] DOLAST
Up-to-date check happens only when the tree of tasks is built and tasks are being executed in order.
Since no value is stored from this check, it is not possible to determine the up-to-date status of a task without executing all tasks it depends on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With