A journey to optimize gradle configuration

Brais Gabín Moreira
21 Buttons Engineering
2 min readSep 12, 2019
Photo by dlritter

There are a lot of posts and talks telling that the configuration phase in gradle should be fast, really fast. At 21 Buttons, it wasn’t. We followed all the tips that those resources pointed out but we couldn’t fix our problem. So, welcome to our journey where we will tell you how we fixed it.

In our case the Dependency Resolution was far too slow as you can check here in this gradle profile log (./gradlew testDebug --profile)

Dependency Resolution has its own section in the log

OK, 15 seconds is far too much. The problem is that --profile gives us the number but it doesn’t reveal any insight of the real problem. So we moved to ./gradlew testDebug --scan. With scan we have more information. In our case there was something interesting inside Performance > Network Activity:

Performance > Network Activity showed us 57 HEAD failed calls

What are all of those HEAD calls against jitpack? We checked and our dependency com.github.magiepooh:recycler-itemdecoration:1.1.2@aar is listed in jitpack and jcenter. But jitpack doesn’t have the version 1.1.2. That version only exists on jcenter. So, in our case, gradle is trying to resolve this version against jitpack every time we run a build. That’s terrible. OK, let’s fix it.

Because Bintray jcenter is not a trustworthy artifact host we have it at the bottom of our repository list:

repositories {
mavenCentral()
google()
maven { url 'https://jitpack.io' }
jcenter()
}

Our solution? Declare a repository filter. This way we get from jitpack only the dependencies that we want from there.

repositories {
mavenCentral()
google()
maven {
url 'https://jitpack.io'
content {
includeModule('com.github.21Buttons', 'scissors')
includeModule('com.github.badoo.mvicore', 'mvicore')
}
}
jcenter()
}

With this trick gradle resolves all our dependencies in 0.8 seconds instead of 15. And more important: the Android Studio sync process improves from 50 seconds to 9 seconds 🎉.

So, be careful how you get your dependencies. You can be losing a lot of time there.

--

--