Skip to content

EngFlow Gradle cache plugin

Experimental

This plugin is currently experimental. Contact EngFlow if you'd like to use it.

The Gradle cache plugin enables you to use EngFlow's distributed Content-Addressable Storage (CAS) as a remote build cache for your Gradle builds. Using a remote cache for your Gradle build's artifacts speeds up development workflows by loading task outputs from the cache whenever available.

The Gradle cache plugin uses gRPC calls to write build artifacts to and fetch them from the CAS. This page describes how to install and configure the plugin.

Set up the EngFlow Gradle cache plugin

To use the EngFlow Gradle cache plugin, your settings.gradle.kt or settings.gradle file must contain plugin and remote cache-specific configuration. The following sections document the blocks you need to add or edit to the file.

Code samples show settings.gradle.kt

All code samples on this page show sections of an example settings.gradle.kt file. If you're using a settings.gradle file, adapt the samples accordingly.

The pluginManagement block

The EngFlow Gradle cache plugin is published as a Maven repository. Configure your pluginManagement block to fetch the plugin from the hosting location. Contact EngFlow for the hosting location details.

Kotlin
pluginManagement {
    repositories {
        // ... other repositories
        maven {
            // url of the hosting location
            url = uri("https://example.com")
            // credentials
            credentials {
                username = 'your-access-key'
                password = 'your-secret-key'
            }
        }
    }
}

The plugins block

Specify com.engflow.cache.gradle in the plugins block to apply the Gradle cache plugin.

Kotlin
1
2
3
4
// apply the plugin
plugins {
    id("com.engflow.cache.gradle")
}

The engflow block

Configure your access to the EngFlow caching cluster using the engflow block. This block requires cluster-specific information provided to you by your contact at EngFlow.

The engflow block contains the cluster and authentication blocks.

Specify the following in the cluster block:

  • endpoint: The EngFlow cluster’s URI. For example, examplename.cluster.engflow.com.
  • instanceName: Include this value only if your cluster has a multitenancy setup.

In the authentication block, depending on how your cluster is configured, specify one of the following methods of authentication:

Kotlin
// configure the plugin with cluster-specific info provided by EngFlow
engflow {
    cluster {
      endpoint = uri("CLUSTER_ENDPOINT")
      // specify only if your cluster has a multitenancy setup
      instanceName = "tenant"
    }

    //  specify one auth method depending on cluster configuration
    authentication {
      // if using credential helper
      credentialHelper = file("<engflow_auth location>")
      // if using mtls
      mtls {
          certificate = file("/path/to/cert.pem")
          privateKey  = file("/path/to/key.pem")
      }
    }
}

The cache block

This block contains the following parameters:

  • push: When true, allows the build to write to the remote cache, assuming that you've provided valid credentials in the engflow.authentication block.
  • enabled: When true, allows the build to apply the plugin and use it for remote caching. When false, the plugin is neither applied nor used for remote caching.
  • chunkSize: The maximum chunk size for writing cache entries. Set this parameter's value to a size that's compatible with your network performance and setup. Note that the deadline parameter's value may also affect the optimal chunkSize. Work with your EngFlow contact to arrive at the optimal value for your use case.
  • deadline: Specify the amount of time (in minutes) to wait before ending a cache operation (read or write). Take the chunkSize into account while setting this value. Work with your EngFlow contact to arrive at the optimal value for your use case.
  • retryBackoff: Specify the delay (in seconds) before retrying the operation.
  • retryJitter: Specify the randomization of the retryBackoff time (in seconds).

Tip

Work with your EngFlow contact to arrive at optimal values for the parameters in the cache block. Specifically, the chunkSize and deadline values are key to acheiving the best possible caching performance.

Kotlin
cache {
    // enable writing to cache
    push = true
    enabled = true
    //maximum chunk size
    chunkSize = (1_048_576 * 4) - 5
    // time to wait before ending remote cache operations
    deadline = java.time.Duration.ofMinutes(1)
    // time to wait before retrying an operation
    retryBackoff = java.time.Duration.ofSeconds(1)
    // jitter for backoff
    retryJitter  = java.time.Duration.ofSeconds(1)
}

Your Gradle cache plugin is now set up to read from and write to the remote cache.