How to ask gradle if something is not relevant

Is there a way to ask gradle if something is not updated and needs to be built (without creating it then)?

+4
source share
1 answer

It's impossible. An updated check occurs at run time, just before launch doFirst. It is calculated, and this value is not saved. Moreover, an updated check may depend on previous tasks. Therefore, to solve the current state of the task, you need to perform all its dependsOntasks. Therefore, what you ask will theoretically work only for the first task, which is not relevant.

To see how the life cycle works, here is a simple example:

task hello {
    println "CONFIG1"
    outputs.upToDateWhen {
        println "UPTODATE"
        return false
    }
    println "CONFIG2"
    doFirst {
        println "DOFIRST"
    }
    doLast {
        println "DOLAST"
    }
}

--debug, :

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

. Gradle :

08:16:26.212 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskGraphExecuter] Timing: Creating the DAG took 0.007 secs

:

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

.

, , , .

+1

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


All Articles