Skip to content
A Gradle build cache that uses Redis to store build artifacts
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
gradle/wrapper
src/main/java/net/idlestate/gradle/caching
.gitignore
LICENSE
README.adoc
build.gradle
gradlew
gradlew.bat
settings.gradle

README.adoc

Gradle - RedisBuildCache

This Gradle plugin provides a build cache implementation that uses Redis to store build artifacts.

Options

The build cache takes the following options:

Option System property Default value

host

net.idlestate.gradle.caching.redis.host

localhost

port

net.idlestate.gradle.caching.redis.port

6379

password

net.idlestate.gradle.caching.redis.password

<no password>

timeToLive

net.idlestate.gradle.caching.redis.ttl

14400 (10 days in minutes)

Usage

There are multiple ways to use the Redis based build cache inside your projects.

As plugin in settings.gradle

settings.gradle
buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'gradle.plugin.net.idlestate:gradle-redis-build-cache:1.2.1'
    }
}

apply plugin: 'net.idlestate.gradle-redis-build-cache'

buildCache {
    local {
        enabled = false
    }
}

Manual registration in settings.gradle

settings.gradle
buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'gradle.plugin.net.idlestate:gradle-redis-build-cache:1.2.1'
    }
}

import net.idlestate.gradle.caching.RedisBuildCache
import net.idlestate.gradle.caching.RedisBuildCacheServiceFactory

buildCache {
    local {
        enabled = false
    }

    registerBuildCacheService( RedisBuildCache.class, RedisBuildCacheServiceFactory.class )

    remote( RedisBuildCache.class ) {
        host = '127.0.0.1'
        port = 6379
        timeToLive = 2*24*60 // two days in minutes
        enabled = true
        push = true
    }
}

Using an init script

init-build-cache.gradle
initscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'gradle.plugin.net.idlestate:gradle-redis-build-cache:1.2.1'
    }
}

import net.idlestate.gradle.caching.RedisBuildCache
import net.idlestate.gradle.caching.RedisBuildCacheServiceFactory

gradle.settingsEvaluated { settings ->
    settings.buildCache {
        local {
            enabled = false
        }

        registerBuildCacheService( RedisBuildCache.class, RedisBuildCacheServiceFactory.class )

        remote( RedisBuildCache.class ) {
            host = '127.0.0.1'
            port = 6379
            enabled = true
            push = true
        }
    }
}
% ./gradlew --build-cache --init-script init-build-cache.gradle <task>

Statistic

The plugin tracks some values to analyse the cache utilisation and adjust the cache and redis settings.

Purpose Redis key format Values

Daily usage

statistic_YYYY-MM-DD

hits

total hits on given date

misses

total misses on given date

key_KEY_hits

hits for KEY on given date

key_KEY_misses

misses for KEY on given date

Key specific usage

key_statistic_KEY

hits

total hits for KEY

misses

total misses for KEY

begin

timestamp of last cache miss

end

timestamp of last cache storage

duration

duration for calculation of cached value

size

size of cached value

License

You can’t perform that action at this time.