Over a million developers have joined DZone.

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

Get the Edge with a Professional Java IDE. 30-day free trial.

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 
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.

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

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 }}