Reputation: 5012
I had the following configuration of my GH Action workflow of a simple Maven project.
name: Java CI
on:
pull_request:
branches:
- master
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Verify with Maven
run: mvn -B -e -ff clean verify
Everything used to work, till I move the Maven project into a code
subdirectory:
name: Java CI
on:
pull_request:
paths:
- code/**
branches:
- master
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Verify with Maven
run: mvn -B -e -ff clean verify --file code/pom.xml
Now in the log I see the cache step says Cache not found for input keys: Linux-maven-xxxxxxx, Linux-maven-
.
Does anyone know why the cache is not working with the project in a subdirectory? Thanks.
Upvotes: 2
Views: 2201
Reputation: 3106
Check to make sure you are not overriding localRepository
in your settings.yaml file. Maven will use default local repository ~/.m2/repository
no matter where you put your project directory.
As a test, you can try to change the maven repository path for artifacts if you are not currently overriding the default local maven repo directory
Add following env variable to your workflow before the jobs start
env:
MAVEN_OPTS: "-Dmaven.repo.local=${{ github.workspace }}/repository"
Then call cache action with the following
- name: Cache Maven repository
uses: actions/cache@v2
with:
path: "${{ github.workspace }}/repository"
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
Upvotes: 1