<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Build Time &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/build-time/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Mon, 12 Oct 2026 06:02:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>How to Decrease Your Gradle Build Time by Up to 65%</title>
		<link>https://www.bestdevops.com/how-to-decrease-your-gradle-build-time-by-65/</link>
					<comments>https://www.bestdevops.com/how-to-decrease-your-gradle-build-time-by-65/#respond</comments>
		
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Mon, 13 Feb 2017 05:12:45 +0000</pubDate>
				<category><![CDATA[DevOps Best Practices]]></category>
		<category><![CDATA[DevOps Process]]></category>
		<category><![CDATA[DevOps Tools]]></category>
		<category><![CDATA[Build Time]]></category>
		<category><![CDATA[Decrease]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Gradle]]></category>
		<category><![CDATA[Gradle Build Cycle]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">http://www.bestdevops.com/?p=625</guid>

					<description><![CDATA[Slow Gradle builds waste developer hours every week. This guide walks through proven configuration techniques — daemon, configure-on-demand, parallel builds, heap tuning, and more — that can cut Android debug build times by 65% or more.]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><em>This article is based on original research and benchmarks published by Keval Patel at kevalpatel2106.wordpress.com. All benchmark figures and commands are drawn from that source.</em></p>



<h2 class="wp-block-heading">Why Build Time Matters</h2>



<p class="wp-block-paragraph">Gradle is a powerful and flexible build system. For Android projects it handles compiling Java source to <code>.dex</code> bytecode, merging resources and assets, packaging everything into an <code>.apk</code>, and signing the result. That flexibility comes at a cost: Gradle is noticeably slower than some alternative build systems.</p>



<p class="wp-block-paragraph">The time lost adds up quickly. If you spend six hours a day on a project and trigger a debug build fifteen times, even a two-and-a-half-minute build time means roughly 35 minutes of idle waiting per day — around 10% of your working hours. Cutting that in half returns meaningful productive time every week.</p>



<p class="wp-block-paragraph">The benchmarks below were measured against the open-source Google I/O Android application, which contains more than 28 dependencies and 41,538 method references — a realistic, non-trivial project. The test machine was a 13-inch MacBook Pro (2016). Your results will vary depending on hardware, project size, and current Gradle version.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1d3wzkk8xca6siekdwgzclq.png?w=660" alt="Gradle build summary showing unoptimised build time"/></figure>



<h2 class="wp-block-heading">Baseline: Build Without Any Optimisations</h2>



<p class="wp-block-paragraph">Before making any changes, measure where you stand. The <code>--profile</code> flag tells Gradle to record the time taken by every task and write an HTML report to <code>/projectDir/build/reports/profile/</code>.</p>


<pre class="wp-block-code"><span><code class="hljs">./gradlew android:assembleDebug --profile</code></span></pre>


<p class="wp-block-paragraph">On the test machine, this produced a baseline of <strong>2 minutes 43 seconds</strong> for a full debug build. That is the number to beat.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1owss_jmy2f5kkozirarolg.png?w=660" alt="Gradle profile report showing baseline build time of 2 min 43 sec"/></figure>



<h2 class="wp-block-heading">Understanding the Gradle Build Lifecycle</h2>



<p class="wp-block-paragraph">Every Gradle build passes through three distinct phases:</p>



<ol class="wp-block-list">
<li><strong>Initialisation</strong> — Gradle determines which projects are part of the build.</li>
<li><strong>Configuration</strong> — Gradle evaluates every <code>build.gradle</code> script, applies plugins, and constructs the task dependency graph.</li>
<li><strong>Execution</strong> — Gradle runs the tasks identified during configuration to actually build the project.</li>
</ol>



<p class="wp-block-paragraph">Only the execution phase does real work. The first two phases are overhead that runs on every invocation. To isolate and measure that overhead, use the <code>--dry-run</code> flag, which forces Gradle to initialise and configure without executing any tasks:</p>


<pre class="wp-block-code"><span><code class="hljs">./gradlew android:assembleDebug --dry-run --profile</code></span></pre>


<p class="wp-block-paragraph">On the Google I/O project, initialisation and configuration alone consumed approximately <strong>7.8 seconds</strong> — time that could be recovered with the right settings.</p>



<h2 class="wp-block-heading">Optimisation 1: Configure on Demand</h2>



<p class="wp-block-paragraph">The Google I/O project contains two modules: <strong>android</strong> (the app) and <strong>server</strong> (backend code). When you build the Android module, Gradle still configures the server module by default — wasting roughly a second for something you do not need.</p>



<p class="wp-block-paragraph">The <code>--configure-on-demand</code> flag tells Gradle to configure only the projects actually required for the requested tasks. Test it like this:</p>


<pre class="wp-block-code"><span><code class="hljs">./gradlew android:assembleDebug --dry-run --profile --configure-on-demand</code></span></pre>


<p class="wp-block-paragraph">To make this permanent, add the following to your <code>gradle.properties</code> file:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">org.gradle.configureondemand=<span class="hljs-literal">true</span></code></span></pre>


<p class="wp-block-paragraph">You can also enable it in Android Studio under <strong>Preferences &gt; Build, Execution, Deployment &gt; Compiler</strong> and checking <em>Configure on demand</em>.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1mbn53rnxiqdfeiwmp9joow.png?w=660" alt="Android Studio compiler preferences showing Configure on Demand checkbox"/></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Benchmark result: ~1 second saved during configuration (~6% improvement on init/config overhead).</p></blockquote>



<h2 class="wp-block-heading">Optimisation 2: Enable the Gradle Daemon</h2>



<p class="wp-block-paragraph">The Gradle Daemon keeps a Gradle JVM process alive in the background between builds. Instead of starting a fresh JVM for every build invocation, subsequent builds reuse the warm process — eliminating JVM startup time and benefiting from JIT-compiled hot paths.</p>



<p class="wp-block-paragraph">The first build after enabling the daemon will not show a speedup because the daemon itself needs to start. Every subsequent build on the same machine will be significantly faster.</p>


<pre class="wp-block-code"><span><code class="hljs">./gradlew android:assembleDebug --dry-run --profile --configure-on-demand --daemon</code></span></pre>


<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1hdjpmnafvlwiwhf4eaqj1q.png?w=660" alt="Gradle profile report showing reduced init and configuration time with daemon enabled"/></figure>



<p class="wp-block-paragraph">To enable the daemon permanently, add to <code>gradle.properties</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">org.gradle.daemon=<span class="hljs-literal">true</span></code></span></pre>


<p class="wp-block-paragraph"><strong>Note:</strong> The Gradle daemon is enabled by default from Gradle 3.0 onwards. If you are already on a modern version you may not need this setting explicitly.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Benchmark result: ~4.5 seconds saved on init/config (~71% improvement on that phase).</p></blockquote>



<h2 class="wp-block-heading">Optimisation 3: Keep Gradle Up to Date</h2>



<p class="wp-block-paragraph">Each Gradle release brings performance improvements. From Gradle 2.4 onwards, Gradle caches build artifacts so that unchanged tasks are skipped on subsequent builds. Newer releases also improve incremental compilation and up-to-date checks.</p>



<p class="wp-block-paragraph">Check your current wrapper version in <code>gradle/wrapper/gradle-wrapper.properties</code> and update the <code>distributionUrl</code> to the latest stable release. You can find the current release on the official Gradle website.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/177iuk0yxgucrmctpnhpexg.png?w=660" alt="gradle-wrapper.properties file showing distributionUrl set to Gradle 3.3"/></figure>



<p class="wp-block-paragraph">After updating the wrapper and re-running with daemon and configure-on-demand, the combined init/config overhead dropped further.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1s4ymdqiraagpzy_h6yja8a.png?w=660" alt="Gradle profile showing further reduced configuration time after upgrading Gradle version"/></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Benchmark result: ~0.7 seconds additional saving on init/config, for a combined ~82% reduction in that phase.</p></blockquote>



<h2 class="wp-block-heading">Optimisation 4: Increase the JVM Heap Size (Dex In Process)</h2>



<p class="wp-block-paragraph">From Android Studio 2.0 onwards (requiring build tools 23.0.2 or higher), the Android Gradle plugin supports <em>dex in process</em>. Previously, each <code>dx</code> (dexing) step spawned a separate JVM process. With dex in process, all <code>dx</code> work runs inside the same JVM as the Gradle daemon, eliminating the overhead of spawning and communicating with child processes.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1l-xjgmxywgvmqyerq7klzw.png?w=660" alt="Diagram showing multiple separate dx processes before dex-in-process"/></figure>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/16jrzzijrnkhphlbyuilafq.png?w=660" alt="Diagram showing unified dex-in-process architecture sharing a single JVM with Gradle daemon"/></figure>



<p class="wp-block-paragraph">Because dex and Gradle now share a single JVM, that JVM needs more heap space. The default daemon heap is approximately 1 GB, which is often too small. Add the following to <code>gradle.properties</code> to increase it:</p>


<pre class="wp-block-code"><span><code class="hljs">org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8</code></span></pre>


<p class="wp-block-paragraph">The right value depends on your machine&#8217;s available RAM and project size. The original author found 3 GB effective for the Google I/O project; increasing beyond that showed diminishing returns on their hardware. Tune this value for your own environment.</p>



<p class="wp-block-paragraph">Running a full clean debug build with these settings combined:</p>


<pre class="wp-block-code"><span><code class="hljs">./gradlew android:assembleDebug --profile --configure-on-demand --daemon</code></span></pre>


<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/12bi_rwf7yseveu-icl7nwg.png?w=660" alt="Gradle profile showing full build time reduced to approximately 1 minute"/></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Benchmark result: Full build dropped from 2 min 43 sec to approximately 1 min — a 63% reduction.</p></blockquote>



<h2 class="wp-block-heading">Optimisation 5: Modularise and Parallelise Your Build</h2>



<p class="wp-block-paragraph">If your project has multiple independent modules, Gradle can build them in parallel rather than sequentially. Enable this with:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">org.gradle.parallel=<span class="hljs-literal">true</span></code></span></pre>


<p class="wp-block-paragraph">The more independent modules your project has, the greater the benefit. For single-module projects or tightly coupled modules, the gain will be minimal. The Google I/O benchmark showed a marginal additional improvement at this stage (cumulative total ~64.5% reduction), because the project does not have many independent subprojects.</p>



<p class="wp-block-paragraph">To maximise the benefit from parallel builds, deliberately structure your codebase into independent feature or library modules that have no circular dependencies on one another.</p>



<figure class="wp-block-image"><img decoding="async" src="https://kevalpatel2106.files.wordpress.com/2017/02/1ynjye8u214hg_4ahinxn1w.png?w=660" alt="Gradle profile showing build time with parallel builds enabled"/></figure>



<h2 class="wp-block-heading">Other Small but Useful Practices</h2>



<h3 class="wp-block-heading">Avoid Heavy Computations in Build Scripts</h3>



<p class="wp-block-paragraph">Configuration-phase code in <code>build.gradle</code> runs on every build. Expensive operations — such as executing a shell command to count Git commits for a version code, or downloading a file from a remote URL — add latency to every single build invocation. Move such operations out of the configuration phase or cache their results.</p>



<h3 class="wp-block-heading">Avoid Dynamic Dependency Versions</h3>



<p class="wp-block-paragraph">Using a trailing <code>+</code> in a dependency version string forces Gradle to contact the remote repository on every build to check for a newer version:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Avoid this — triggers a network round-trip on every build</span>
compile <span class="hljs-string">'com.android.support:appcompat-v7:23.0.+'</span></code></span></pre>


<p class="wp-block-paragraph">Pin to an exact version instead, and update dependencies deliberately:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Prefer this — resolved from cache</span>
compile <span class="hljs-string">'com.android.support:appcompat-v7:23.0.2'</span></code></span></pre>


<h2 class="wp-block-heading">TL;DR — The Complete gradle.properties Configuration</h2>



<p class="wp-block-paragraph">Add the following lines to your project&#8217;s <code>gradle.properties</code> file to apply all of the above optimisations at once:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Keep the Gradle JVM alive between builds</span>
org.gradle.daemon=<span class="hljs-keyword">true</span>

<span class="hljs-comment"># Only configure projects needed for the requested tasks</span>
org.gradle.configureondemand=<span class="hljs-keyword">true</span>

<span class="hljs-comment"># Build independent modules in parallel</span>
org.gradle.parallel=<span class="hljs-keyword">true</span>

<span class="hljs-comment"># Increase heap to support dex-in-process</span>
<span class="hljs-comment"># Adjust -Xmx to suit your machine's available RAM</span>
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=<span class="hljs-number">512</span>m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF<span class="hljs-number">-8</span></code></span></pre>


<p class="wp-block-paragraph">These settings, combined with keeping your Gradle wrapper version current and pinning dependency versions, produced a roughly <strong>65% reduction</strong> in debug build time on the Google I/O project in the original benchmarks.</p>



<h2 class="wp-block-heading">Summary of Benchmark Results</h2>



<figure class="wp-block-table"><table><thead><tr><th>Optimisation applied</th><th>Measured saving</th></tr></thead><tbody><tr><td>Configure on demand</td><td>~1 s (6% of init/config time)</td></tr><tr><td>+ Gradle Daemon</td><td>~4.5 s (71% of init/config time)</td></tr><tr><td>+ Updated Gradle version</td><td>~0.7 s additional (82% cumulative)</td></tr><tr><td>+ Increased heap / dex in process (full build)</td><td>1 min 43 s saved (63% of total build)</td></tr><tr><td>+ Parallel builds</td><td>~64.5% cumulative total build reduction</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><em>All figures are from benchmarks run on a 13-inch MacBook Pro (2016) against the Google I/O open-source Android project. Results on your hardware and project will differ.</em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/how-to-decrease-your-gradle-build-time-by-65/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
