Europe Union
Published: 25/09/2023

Kotlin & Gradle: a perfect match

It’s not a match because they depend on each other and have no choice. It’s a match because they cooperate and complement each other.

Why Kotlin, why Gradle, and why both?

At, we love using Kotlin as a main backend programming language in projects developed for our clients. We find it an elegant, quickly-evolving, type-safe, function and concurrency-focused but still compatible alternative to Java. Having coroutines feature, Arrow-KT library and their limited complexity, it’s easier for us to build performant functional software and to catch most concurrent bugs at compile time.

Gradle, in turn, does an excellent job of building & packaging software, being a tool that is Docker-friendly, fast, and that allows us to write build scripts in the same favorite language for main backend development, Kotlin.

In many cases, the ease of working with a whole toolbox is about more than how well one technology or tool works on its own but how well it fits in, how well it co-operates and how much other pieces of technology complement its downside. This is what I consider a handy toolbox.

Let me show you a few fantastic highlights of writing elegant build scripts using the mentioned technology pair.

Expressing version dependencies as code

We can easily add custom logic with utility functions to hierarchical data and separate dependencies versions and definitions and use them in separate files. The example below demonstrates expressing different kotest dependencies in the same version and kotest extensions in specified versions.

Building docker image with code

We chose Jib and its Gradle plugin to build optimized docker images fast.

Smart and fast building

Software development takes the form of loops. The most inner one is writing code, compiling it and testing it. The shorter the loop is, the quicker development can go. All three mentioned steps can be accomplished well in IntelliJ as it allows fast incremental recompilation and running hand-picked tests. Additionally, IntelliJ can perform static syntax analysis on the fly using CheckStyle or Detekt plugin.

Gradle is best used as a final building and packaging tool for verification. It can build a working version locally or on a Continuous Integration server either before code review or for deployment. Gradle can be installed into the repository and run as a wrapper to choose and bind specific versions with the repository:

Then being run as a wrapper (gradlew) allows running any implemented task, most often testing, building or running.

Longer waiting time for the software to build tests the developer’s patience and creates opportunities to get into a different task context. Gradle has been built with performance in mind and has multiple ways to improve building speed. First, whether the whole project is small enough to build fast and cannot be split into smaller parts to maintain logical consistency should be questioned. Then, allocating significant heap for Gradle, parallel execution and build caching are recommended optimisation options. Additionally, the Gradle internal tool, build scan, finds the biggest time waste and remote build cache can improve building time for the developers.

Experience above knowledge

All in all, you must try it out to build a small pet project or complete a proof of concept of one of your projects with Kotlin and Gradle to understand whether this pair fits your needs and solves more problems than adds complexity.

If you want to engage our experts and learn more about Kotlin features or build your product with us, don’t hesitate to reach out.

Learn more

Estimate your project.

Just leave your email address and we’ll be in touch soon
ornament ornament