# Using Gradle build cache with Kotlin

DevFeed: [Using Gradle build cache with Kotlin](<https://devfeed.tech/articles/using-gradle-build-cache-with-kotlin-24663.md>)

Original publisher: [Read original article](<https://blog.gradle.org/kotlin-build-cache-use>)

Author: Eric Wendelin

Published: 2018-02-06T05:00:00Z

Content type: tutorial

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Caching](<https://devfeed.tech/topics/caching.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [build performance](<https://devfeed.tech/topics/build-performance.md>), [ci](<https://devfeed.tech/topics/ci.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [caching](<https://devfeed.tech/tags/caching.md>), [ci](<https://devfeed.tech/tags/ci.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [git](<https://devfeed.tech/tags/git.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [test](<https://devfeed.tech/tags/test.md>)

## AI overview

This tutorial explains how to use Gradle's build cache with Kotlin to avoid unnecessary compilation and speed up builds. It demonstrates populating and reusing a local cache with Spek, reports a roughly fivefold faster rebuild, and outlines the required Gradle and Kotlin versions.

## Source excerpt

A build cache allows Gradle to reuse task output from any previous invocation, including those from other machines. Kotlin 1.2.21 allows Kotlin projects to make use of build caching. The build cache works by storing compiled classes, test outputs, and other build artifacts in a cache, taking into account all task inputs, including input file contents, relevant classpaths, and task configuration. This frequently results in faster builds. The following chart shows aggregated build time with and without the build cache for part of Gradle's CI: In this post, we'll explain how you can use Gradle's build cache to avoid unnecessary Kotlin compilation to speed up your builds. Quick demo with Spek You can try out build caching with Gradle right now. Just follow these steps: Clone Spek git clone https://github.com/spekframework/spek.git cd spek The Spek 2.x branch (which is the default) already has all prerequisites for build caching that we'll describe later. Build and populate cache The following command builds Spek and populates the local build cache. ❯ ./gradlew assemble --build-cache BUILD SUCCESSFUL in 10s 21 actionable tasks: 21 executed Using the --build-cache flag is one way to tell Gradle to store outputs in a separate task output cache. Remove/change build outputs This simulates being on another machine or perhaps making a change and stashing it. The quickest way to demonstrate is use the clean task. ❯ ./gradlew clean Re-build and resolve from build cache This time when we re-build, all Kotlin compiled sources are pulled from the build cache. ❯ ./gradlew assemble --build-cache BUILD SUCCESSFUL in 2s 21 actionable tasks: 11 executed, 10 from cache Voilà! You just used Gradle's build cache to reuse Kotlin compiled classes instead of recompiling again! The build was about 5x faster! You can see from this build scan that Kotlin compile tasks were pulled from the build cache; :jar and :processResources tasks were not because it's faster to generate JARs and copy files l