Shipfox
Shipfox Caching

Gradle

Speed up Gradle builds with Shipfox's colocated HTTP build cache

Gradle Build Cache stores the outputs of build tasks so they can be reused when the inputs haven't changed. With a shared remote cache, all CI jobs and developer machines can benefit from work done by previous builds.

Shipfox provides a built-in HTTP build cache for Gradle on every runner at $SHIPFOX_GRADLE_URL. The cache is served from the same infrastructure as your runner, making reads and writes significantly faster than connecting to an external server.

How it works

When Gradle executes a task (compiling, testing, generating resources), it computes a hash of the task's inputs. If a matching entry is found in the remote cache, the output is pulled directly and the task is skipped. Otherwise, the task runs normally and its output is pushed to the cache for future use.

Shipfox exposes a WebDAV-backed HTTP build cache endpoint compatible with Gradle's HttpBuildCache. In automatic mode, Shipfox writes a Gradle init script to ~/.gradle/init.d/shipfox-cache.gradle before your job starts so all Gradle invocations use the remote cache automatically.

Automatic setup

When automatic caching is enabled, Shipfox creates the following init script at ~/.gradle/init.d/shipfox-cache.gradle on every runner before your job starts:

gradle.startParameter.buildCacheEnabled = true
gradle.settingsEvaluated { settings ->
    settings.buildCache {
        remote(HttpBuildCache) {
            url = '<shipfox-cache-url>'
            push = true
            allowInsecureProtocol = true
        }
    }
}

All gradle build, gradle compileJava, and other Gradle tasks automatically use the remote cache, with no changes to your project files needed.

- uses: actions/setup-java@v5
  with:
    distribution: temurin
    java-version: '21'

- name: Build
  run: ./gradlew build

Automatic caching is enabled by default. You can disable it per tool from your Organization Settings in the Shipfox dashboard if you prefer to manage the configuration yourself.

Manual setup

If you want full control over the cache configuration, use the $SHIPFOX_GRADLE_URL environment variable exposed on every runner.

Option 1: Configure in settings.gradle.kts:

buildCache {
    remote<HttpBuildCache> {
        url = uri(System.getenv("SHIPFOX_GRADLE_URL") ?: "")
        isPush = true
        isAllowInsecureProtocol = true
    }
}

Then enable build cache in your workflow:

- name: Build
  run: ./gradlew build --build-cache

Option 2: Write an init script in your workflow:

- name: Configure Gradle remote cache
  run: |
    mkdir -p ~/.gradle/init.d
    cat > ~/.gradle/init.d/shipfox-cache.gradle << 'EOF'
    gradle.startParameter.buildCacheEnabled = true
    gradle.settingsEvaluated { settings ->
        settings.buildCache {
            remote(HttpBuildCache) {
                url = System.getenv("SHIPFOX_GRADLE_URL")
                push = true
                allowInsecureProtocol = true
            }
        }
    }
    EOF

- name: Build
  run: ./gradlew build

allowInsecureProtocol = true (or isAllowInsecureProtocol = true in Kotlin DSL) is required because the Shipfox cache endpoint uses HTTP within the runner network.