Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github-actions: cache repo to speed up maven builds

Maven dependencies are downloaded every time my build workflow is triggered.

Travis CI provides a way to cache maven repository. Does Github actions provider similar functionality that allows to cache maven repository?

like image 549
Sudhir Avatar asked Aug 28 '19 15:08

Sudhir


People also ask

Does Maven have a cache?

At very simple form, the build cache Maven is essentially a hash function which takes Maven project and produces cache key for a project.

What is Maven cache?

the local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.


2 Answers

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.

like image 154
Rob van der Leek Avatar answered Oct 12 '22 04:10

Rob van der Leek


Apparently as of 10 September 2019 caching of build dependencies is not present in Github Actions. Github staff have acknowledged that this feature is necessary, and have replied that "We're working on caching packages and artifacts between workflow executions, we'll have it by mid-November [2019]."

Source: https://github.community/t5/GitHub-Actions/Caching-files-between-GitHub-Action-executions/m-p/30974/highlight/true#M630

like image 38
abyrd Avatar answered Oct 12 '22 04:10

abyrd