When using cache: maven, the action caches ~/.m2/repository. Because Maven resolves plugins lazily, a standard mvn compile might not download all necessary plugin dependencies. If these are missing, subsequent jobs (like test or package) will re-download them every time because the action does not re-save the cache on a hit.
To fix this, run a "seed" command to resolve all dependencies and plugins before your main build.
Recommended Seed Commands
| Command | Resolves plugin dependencies? | Notes |
|---|
mvn dependency:resolve | No | Project dependencies only. |
mvn dependency:resolve-plugins | Yes | Plugins and their dependencies. |
mvn dependency:go-offline | Yes | Project and plugin dependencies (superset). |
mvn dependency:go-offline dependency:resolve-plugins | Yes | Recommended default for thoroughness. |
Implementation Patterns
Pattern 1: Single job (Seed then Build)
Use this if you want the seed and build to happen in one job. The cache is saved at the end of this run.
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: 'temurin'
java-version: '25'
cache: 'maven'
- name: Seed the Maven cache
run: mvn dependency:go-offline dependency:resolve-plugins
- name: Build with Maven
run: mvn verify --file pom.xml
Pattern 2: Separate seed job (Matrix friendly)
Use this for matrix builds where multiple jobs share the same cache. The seed-cache job creates a comprehensive cache that all subsequent jobs reuse.
jobs:
seed-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: 'temurin'
java-version: '25'
cache: 'maven'
- name: Seed the Maven cache
run: mvn dependency:go-offline dependency:resolve-plugins
build:
needs: seed-cache
runs-on: ubuntu-latest
strategy:
matrix:
goal: ['test', 'verify', 'test -Pprofile1']
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v6
with:
distribution: 'temurin'
java-version: '25'
cache: 'maven'
- name: Build
run: mvn ${{ matrix.goal }} --file pom.xml