# sbt Build Cache

import { Aside } from '@astrojs/starlight/components';

Avrea provides a remote cache for [sbt 2](https://www.scala-sbt.org/2.x/docs/en/concepts/caching.html).
Task results such as compilation are cached, so a build with unchanged inputs
restores them instead of running the tasks again.

Requires sbt 2.1.0 or newer. For dependency downloads, see
[Maven / Gradle Packages](/cache/packages/maven/).

## On Avrea runners

The cache location is pre-configured. Add sbt's remote cache plugin to your
project to use it:

```scala title="project/plugins.sbt"
addRemoteCachePlugin
```

That line is all your repository needs. Outside Avrea runners no cache location
is set, so the plugin does nothing there.

If your job sets `SBT_CONFIG_HOME` or, on Linux and macOS, its own
`XDG_CONFIG_HOME`, sbt reads its global settings from that location instead of
the one Avrea provides. Add a settings file to the `2` subdirectory of the sbt
directory your job uses, for example `$SBT_CONFIG_HOME/2/avrea-remote-cache.sbt`:

```scala title="avrea-remote-cache.sbt"
Global / remoteCache := Some(uri("http://cache.avrea.com:8290/sbt-build"))
```

Your workflow needs no changes:

```yaml title="workflow.yml"
jobs:
  build:
    runs-on: avrea-ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: '21'
      - uses: sbt/setup-sbt@v1
      - run: sbt test
```

sbt reports cache use at the end of each command:

```text
[success] elapsed time: 0 s, cache 100%, 1 disk cache hit, 2 remote cache hits
```

<Aside>
sbt prints a warning that the cache uses the plaintext `http://` scheme. The
cache is colocated with the runner and reachable only from it.
</Aside>

## Using your own remote cache

If your build sets `Global / remoteCache` itself, Avrea leaves it alone and your
cache is used.

To turn the Avrea sbt cache off for a repository, see
[Managing caches](/cache/managing/).