Skip to content

Commit

Permalink
Adds save & restore gradle dependency cache scripts (#25)
Browse files Browse the repository at this point in the history
* Adds save & restore gradle dependency cache scripts

* Add backticks to comments in restore & save gradle dependency cache scripts

Co-authored-by: Gio Lodi <giovanni.lodi42@gmail.com>

Co-authored-by: Gio Lodi <giovanni.lodi42@gmail.com>
  • Loading branch information
oguzkocer and mokagio authored May 17, 2022
1 parent e25ca75 commit e1a681b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/restore_gradle_dependency_cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -eu

# The key is shared with `bin/save_gradle_dependency_cache`
GRADLE_DEPENDENCY_CACHE_KEY="GRADLE_DEPENDENCY_CACHE"

echo "Restoring Gradle dependency cache..."

# `save_cache` & `restore_cache` scripts only work if they are called from the same directory
pushd "$GRADLE_RO_DEP_CACHE_BASE_FOLDER"
restore_cache "$GRADLE_DEPENDENCY_CACHE_KEY"
popd

echo "---"
22 changes: 22 additions & 0 deletions bin/save_gradle_dependency_cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -eu

# The key is shared with `bin/restore_gradle_dependency_cache`
GRADLE_DEPENDENCY_CACHE_KEY="GRADLE_DEPENDENCY_CACHE"

echo "Saving Gradle dependency cache..."

mkdir -p "$GRADLE_RO_DEP_CACHE"

# https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:cache_copy
# Gradle suggests removing the `*.lock` files and the `gc.properties` file before saving cache
cp -r ~/.gradle/caches/modules-2 "$GRADLE_RO_DEP_CACHE" \
&& find "$GRADLE_RO_DEP_CACHE" -name "*.lock" -type f -delete \
&& find "$GRADLE_RO_DEP_CACHE" -name "gc.properties" -type f -delete

# `save_cache` & `restore_cache` scripts only work if they are called from the same directory
pushd "$GRADLE_RO_DEP_CACHE_BASE_FOLDER"
# For now we are using a single key - we might expand on this later by using dependency catalog version
save_cache "$GRADLE_RO_DEP_CACHE_FOLDER_NAME" "$GRADLE_DEPENDENCY_CACHE_KEY" --force
popd

echo "---"

0 comments on commit e1a681b

Please sign in to comment.