# Maven Build Cache

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

Avrea provides a cache endpoint for the [Maven Build Cache Extension](https://maven.apache.org/extensions/maven-build-cache-extension/).
Build outputs are cached so that modules with unchanged inputs skip recompilation.

## On Avrea runners

The cache URL is pre-configured via `MAVEN_OPTS`:

```bash
MAVEN_OPTS="-Dmaven.build.cache.remote.url=http://cache.avrea.com:8290/maven-build/cache \
  -Dmaven.build.cache.remote.enabled=true \
  -Dmaven.build.cache.remote.save.enabled=true"
```

You need to add the **build cache extension** to your project:

```xml title=".mvn/extensions.xml"
<!-- .mvn/extensions.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
    <groupId>org.apache.maven.extensions</groupId>
    <artifactId>maven-build-cache-extension</artifactId>
    <version>1.2.2</version>
  </extension>
</extensions>
```

```xml title=".mvn/maven-build-cache-config.xml"
<!-- .mvn/maven-build-cache-config.xml -->
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0">
  <configuration>
    <enabled>true</enabled>
    <hashAlgorithm>SHA-256</hashAlgorithm>
    <remote enabled="true" id="avrea-cache">
      <url>http://cache.avrea.com:8290/maven-build/cache</url>
    </remote>
  </configuration>
</cache>
```

<Aside>
These extension XML files are committed to your repository.
</Aside>

The build cache extension is required regardless of runner environment.

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'
      - run: mvn verify
```