Speeding up Gradle builds

Runtime, build and Gradle Mid-level Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Pick the fix

Changing one string in a feature module recompiles almost every module. What's the likely cause?

Options
Hint 1 of 1

What decides which modules see a change?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Modules expose each other with api and share transitive R classes

Correct. Changes ripple through everything that sees them.

Why not the others?
  • B Not enough RAM. Memory affects speed, not what recompiles.
  • C The Gradle wrapper is old. Unlikely to cause wide recompilation.
  • D Too many unit tests. Tests don't affect what recompiles.

30-second answer

Measure first with a Build Scan or the Build Analyzer. Then the usual wins: turn on the configuration cache and build cache, replace kapt with KSP, split code into modules with implementation dependencies so changes recompile less, avoid work at configuration time, keep plugins and AGP up to date, and give Gradle enough memory. Non-transitive R classes also cut recompilation.

Practise saying it · 30 s. No recording, just a timer

Explain how to speed up builds.

Say your answer out loud, then check which of these points you covered:

  • Measure with Build Analyzer or scans
  • Configuration and build cache
  • KSP over kapt
  • Modules with implementation
  • No config-time work

Deep dive

The configuration cache skips the configuration phase when build files haven't changed.

api dependencies leak to consumers and widen recompilation; prefer implementation.

Convention plugins in build-logic keep module build files small and consistent.

A remote build cache shares outputs between CI and developers.

Common mistakes

  • Guessing instead of profiling.
  • One giant app module.
  • Network calls or file scans in build scripts at configuration time.

Senior take & follow-ups

Lead with 'measure', then list wins in order of impact.

Follow-up questions

Think of your answer first, then open the hint.

  1. What's the difference between the build cache and configuration cache?

    Show hint

    Build cache reuses task outputs; configuration cache reuses the task graph.

  2. Why do non-transitive R classes help?

    Show hint

    Each module's R class only has its own resources, so fewer files recompile.

Suggest a fix if something here is wrong or out of date.