Github-actions: cache repo to speed up maven builds
For completeness, this is an example of how to cache the local Maven repository on subsequent builds:
steps:
# Typical Java workflow steps
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
# Step that does that actual cache save and restore
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Step that runs the tests
- name: Run tests
run: mvn test
See this page for more details.
As of 2021, the most up to date official answer would be
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
taken from an official github example at https://github.com/actions/cache/blob/master/examples.md#java---maven