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

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:
gradle ,java ,incremental tasks ,tutorial

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}