Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask gradle if anything is not up-to-date

Tags:

gradle

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)?

like image 972
James Avatar asked Feb 06 '17 09:02

James


People also ask

How does gradle determine up to date?

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.

How to debug Gradle?

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.

What is incremental build in gradle?

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.


1 Answers

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.

like image 199
MartinTeeVarga Avatar answered Sep 21 '22 02:09

MartinTeeVarga