Improving gradle tasks performance

To measure the time taken by any task in Gradle , we can use the option “profile” as follows

./gradlew –profile

The above command generates a detailed HTML report with the following Tabs.

Summary: Gives the overall time of the task executed.
Configuration: Time taken by each project present in the given task.
Dependency resolution: Shows the times for resolving all the dependencies
Task Execution: shows time taken by each task, this can help you to trace which task is taking more time and act accordingly.

Therefore as part of optimizing build task , –profile helps in generating the detailed report of which task is taking which time.

Following tasks are identified as taking more time for build task

distTar, distZip, bootDistTar, bootStartScripts, bootDistZip

Next step is how to ignore these tasks if not required ?
Gradle provide the option ./gradlew -x

Usage example:

./gradlew build –info -x distTar -x distZip -x bootDistTar -x bootDistZip

In addition we can also use the option “–build-cache” to improve the performance of any build target.
build cache is a cache mechanism that aims to save time by reusing outputs produced by other builds.

More inforation about build cache:
https://docs.gradle.org/current/userguide/build_cache.html

Therefore Going forward, we can use the same approach for optimizing/analysing any Gradle task.

Leave a comment