Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gradle Goodness: Run Tasks Ignoring Up-to-Date Checks [Code Snippet]

DZone's Guide to

Gradle Goodness: Run Tasks Ignoring Up-to-Date Checks [Code Snippet]

You can use Gradle for builds for incremental tasks, building only when things change. This quick code snippet introduces the assemble and rerun task commands

· Java Zone ·
Free Resource

Akka from A to Z, An Architects Guide starting off with Actors and Akka Streams, then on to clustering, sharding, event sourcing & CQRS, and more. 

Gradle builds are fast because Gradle supports incremental tasks. This means Gradle can determine if input or output of tasks has changed — before running the task. If nothing has changed, a task is marked as up-to-date and the task is not executed. Otherwise, the task is executed. If we want to execute a task even if it is up-to-date we must use the command line option --rerun-tasks.

In the following example, we run the assemble task for a simple Java project, and we see all tasks are executed. When we invoke the assemble task again we see the tasks are all up-to-date:

$ gradle assemble :compileJava :processResources :classes :jar :assemble 
BUILD SUCCESSFUL Total time: 1.765 secs 
$ gradle assemble 
:compileJava UP-TO-DATE 
:processResources UP-TO-DATE 
:classes UP-TO-DATE 
:jar UP-TO-DATE 
:assemble UP-TO-DATE BUILD SUCCESSFUL 
Total time: 0.715 secs 
$ 

To run all tasks without an up-to-date check we use the option --rerun-tasks:

Written with Gradle 3.2.1.

Akka from A to Z, An Architects Guide starting off with Actors and Akka Streams, then on to clustering, sharding, event sourcing & CQRS, and more. 

Topics:
gradle ,java ,incremental tasks ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}