Reputation: 14479
As the docs state in order to cache the Maven dependencies with GitHub Actions all we have to use is the actions/cache action like this:
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
However using the windows-2016
GitHub Actions environment, this doesn't provides us with a working cache - as the logs states:
Post job cleanup.
"C:\Program Files\Git\usr\bin\tar.exe" --posix --use-compress-program "zstd -T0" -cf cache.tzst -P -C D:/a/spring-boot-admin/spring-boot-admin --files-from manifest.txt --force-local
/usr/bin/tar: C\:\\Users\runneradmin\\.m2\repository: Cannot stat: No such file or directory
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Tar failed with error: The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2
How to fix this?
Upvotes: 2
Views: 2796
Reputation: 14479
It seems that the path to the Maven repository isn't correctly initialized. As this issue describes the paths are written with \\
instead of /
which GNU tar expects. The fix was already provided in Dec 2020, so it made it to the version v2.1.4
. The last version v2.1.3
was released in November. But sadly there is a bug in pointing the v2
to the latest v2.1.4
(as normally expected by GitHub Actions users). Therefore to solve this issue, we need to explicitely specifiy the full actions/cache version v2.1.4
like this:
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/[email protected]
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
Now it should work like a charm (see logs here).
Upvotes: 4