Incremental testing for Gradle multi-projects

Patxi Bocos
The Startup
Published in
3 min readJul 16, 2019

--

Application modularization is something pretty common on Android, even Google talked about it in last I/O. Whether you use it just to separate different domains or to implement a clean architecture with multiple layers, you will end up with multiple Gradle subprojects. One of the benefits of modularizing your app is accelerating the build times, but you can go further.

Each of the subprojects will probably have some tests (hopefully) which will be ran both on your local machine and in some CI system. When someone raises a PR on project’s Git repository, some workflow will be triggered to run the tests, measure coverage, run linters, etc. If your app is based on a large codebase with several tests, this can take long. Can we do something to avoid running all the tests everytime? Maybe a PR is modifying a single class on a subproject, and we don’t need to run tests on every subproject.

In order to improve this, we are going to build a Gradle task which does the following:

  • Detect which files have been added/modified/removed in some branch, compared to another one (base).
  • Identify which Gradle subprojects belong those files to.
  • For each of the subprojects, traverse recursively every other subprojects to collect which ones are depending on them.

--

--

Patxi Bocos
The Startup

Impure developer and functional programming enthusiast