Skip to content

Commit 0535a28

Browse files
committed
Use actions/setup-java caching abilities
The support of sbt caching has been implement recently in actions/setup-java#302 and actions/setup-java#332 by Florian Meriaux
1 parent 2d88fdb commit 0535a28

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

src/reference/02-DetailTopics/05-Plugins-and-Best-Practices/04-GitHub-Actions-with-sbt.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Checkout
4848
uses: actions/checkout@v2
4949
- name: Setup JDK
50-
uses: actions/setup-java@v2
50+
uses: actions/setup-java@v3
5151
with:
5252
distribution: temurin
5353
java-version: 8
@@ -89,7 +89,7 @@ jobs:
8989
- name: Checkout
9090
uses: actions/checkout@v2
9191
- name: Setup JDK
92-
uses: actions/setup-java@v2
92+
uses: actions/setup-java@v3
9393
with:
9494
distribution: temurin
9595
java-version: 8
@@ -117,24 +117,24 @@ java
117117

118118
You can speed up your `sbt` builds on GitHub Actions by caching various artifacts in-between the jobs.
119119

120-
Here are sample caching steps that you can use:
120+
The action `setup-java` has built-in support for caching artifacts downloaded by
121+
sbt when loading the build or when building the project.
122+
123+
To use it, set the input parameter `cache` of the action `setup-java` to the value `"sbt"`:
121124

122125
```yml
123-
- name: Coursier cache
124-
uses: coursier/cache-action@v6
126+
- name: Setup JDK
127+
uses: actions/setup-java@v3
128+
with:
129+
distribution: temurin
130+
java-version: 8
131+
cache: sbt
125132
- name: Build and test
126133
run: sbt -v +test
127-
- name: Cleanup before cache
128-
shell: bash
129-
run: |
130-
rm -rf "\$HOME/.ivy2/local" || true
131-
find \$HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
132-
find \$HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
133-
find \$HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
134-
find \$HOME/.sbt -name "*.lock" -delete || true
135134
```
136135
137-
With the above changes combined GitHub Actions will tar up the cached directories and uploads them to a cloud storage provider.
136+
Note the added line `cache: sbt`.
137+
138138
Overall, the use of caching should shave off a few minutes of build time per job.
139139

140140
### Build matrix
@@ -170,7 +170,7 @@ jobs:
170170
- name: Checkout
171171
uses: actions/checkout@v2
172172
- name: Setup JDK
173-
uses: actions/setup-java@v2
173+
uses: actions/setup-java@v3
174174
with:
175175
distribution: temurin
176176
java-version: \${{ matrix.java }}
@@ -210,7 +210,7 @@ jobs:
210210
- name: Checkout
211211
uses: actions/checkout@v2
212212
- name: Setup JDK
213-
uses: actions/setup-java@v2
213+
uses: actions/setup-java@v3
214214
with:
215215
distribution: temurin
216216
java-version: \${{ matrix.java }}
@@ -267,12 +267,11 @@ jobs:
267267
- name: Checkout
268268
uses: actions/checkout@v2
269269
- name: Setup JDK
270-
uses: actions/setup-java@v2
270+
uses: actions/setup-java@v3
271271
with:
272272
distribution: temurin
273273
java-version: \${{ matrix.java }}
274-
- name: Coursier cache
275-
uses: coursier/cache-action@v6
274+
cache: sbt
276275
- name: Build and test (1)
277276
if: \${{ matrix.jobtype == 1 }}
278277
shell: bash
@@ -288,14 +287,6 @@ jobs:
288287
shell: bash
289288
run: |
290289
sbt -v "dependency-management/*"
291-
- name: Cleanup before cache
292-
shell: bash
293-
run: |
294-
rm -rf "\$HOME/.ivy2/local" || true
295-
find \$HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
296-
find \$HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
297-
find \$HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
298-
find \$HOME/.sbt -name "*.lock" -delete || true
299290
```
300291

301292
### sbt-github-actions

0 commit comments

Comments
 (0)