Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

AWS S3 Gradle build cache

Apache License 2.0 GitHub version Build status

This is a custom Gradle build cache implementation which uses AWS S3 to store the cache objects.


  • Version >= 0.3.0 - Gradle 4.x
  • Version < 0.3.0 - Gradle 3.5

Use in your project

Please note that this plugin is not yet ready for production. Feedback though is very welcome. Please open an issue if you find a bug or have an idea for an improvement.

Apply plugin

The Gradle build cache needs to be configured on the Settings level. As a first step, add a dependency to the plugin to your settings.gradle file. Get the latest version from Gradle plugin portal.

buildscript {
  repositories {
    maven {
      url ""
  dependencies {
    classpath "<version>"


The AWS S3 build cache implementation has a few configuration options:

Configuration Key Description Mandatory Default Value
region The AWS region the S3 bucket is located in. yes
bucket The name of the AWS S3 bucket where cache objects should be stored. yes
path The path under which all cache objects should be stored. no
reducedRedundancy Whether or not to use reduced redundancy. no true
endpoint Alternative S3 compatible endpoint no
headers A map with HTTP headers to be added to each request (nulls are ignored). e.g. [ 'x-header-name': 'header-value' ] no
awsAccessKeyId The AWS access key id no from DefaultAWSCredentialsProviderChain
awsSecretKey The AWS secret key no from DefaultAWSCredentialsProviderChain
sessionToken The AWS sessionToken when you use temporal credentials no from DefaultAWSCredentialsProviderChain

The buildCache configuration block might look like this:

 apply plugin: 'ch.myniva.s3-build-cache'
 ext.isCiServer = System.getenv().containsKey("CI")
 buildCache {
     local {
         enabled = !isCiServer
     remote(ch.myniva.gradle.caching.s3.AwsS3BuildCache) {
         region = 'eu-west-1'
         bucket = 'your-bucket'
         push = isCiServer

More details about configuring the Gradle build cache can be found in the official Gradle documentation.

AWS credentials

The plugin uses the DefaultAWSCredentialsProviderChain to look up the AWS credentials. If you want to override the credentials feel free to set awsAccessKeyId and awsSecretKey and (optionally depends on configuration) sessionToken. If they are set the plugin will ignore DefaultAWSCredentialsProviderChain.

S3 Bucket Permissions

The AWS credential must have at least the following permissions to the bucket:

  "Version": "2012-10-17",
  "Statement": [
      "Effect": "Allow",
      "Action": [
      "Resource": [

Expiring cache entries

This plugin does not deal with expiring cache entries directly but relies on S3 object lifecycle management to do so. Cache entry expiration rules can be set on S3 buckets using AWS API or via AWS Management Console.


Contributions are always welcome! If you'd like to contribute (and we hope you do) please open a pull request.


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.