Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gradle Goodness: Change Local Build Cache Directory [Snippet]

DZone's Guide to

Gradle Goodness: Change Local Build Cache Directory [Snippet]

Gradle's build cache is an important feature in Gradle 3.5. Individual project caches are something you want fine control over the location of.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Gradle 3.5 introduced the build cache. With the build cache, we can reuse task output from builds that can come from different computers. We can also use the build cache feature for our local builds. By default the directory to store the cache is located in the Gradle user home directory on our computer (USER_HOME/.gradle/caches/build-cache-1). We can change the directory for the local cache via settings.gradle of our Gradle project. For example, we could configure a directory in our project file structure to be the build cache directory. Then it is easy to clean the cache because it is a directory not shared by other Gradle projects. With the default directory location in the Gradle user home directory, the caches of all Gradle projects we run on our computer are stored in a single directory. And because the cache doesn't shrink and will only grow, we might want to have more control of where the cache of a single Gradle project is stored. This way, we can easily clean the cache because all files of a project are stored in the directory for that project.

In the following settings.gradle file, we configure our build cache directory to be the directory build-cache in the root directory of our project where we store our settings.gradle file:

// File: settings.gradle
buildCache {
    local {
        // Set local build cache directory.
        directory = "${settingsDir}/build-cache"
    }
}

Written with Gradle 3.5.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:
java ,groovy ,gradle ,build cache

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}