-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
VERSION --global-cache 0.7 | ||
|
||
|
||
# GRADLE_GET_MOUNT_CACHE sets the following entries in the calling environment: | ||
# EARTHLY_GRADLE_USER_HOME_CACHE: Code of the mount cache for the gradle home. | ||
# EARTHLY_GRADLE_PROJECT_CACHE: Code of the mount cache for the .gradle folder. | ||
# Example: | ||
# DO gradle+GRADLE_GET_MOUNT_CACHE | ||
# RUN --mount=$EARTHLY_GRADLE_USER_HOME_CACHE --mount=$EARTHLY_GRADLE_PROJECT_CACHE gradle --no-daemon build | ||
# Arguments: | ||
# - cache_prefix: To be used in both caches. By default: ${EARTHLY_TARGET_PROJECT_NO_TAG}#${OS_RELEASE}#earthly-gradle-cache | ||
GRADLE_GET_MOUNT_CACHE: | ||
COMMAND | ||
ARG EARTHLY_TARGET_PROJECT_NO_TAG | ||
ARG cache_prefix = "${EARTHLY_TARGET_PROJECT_NO_TAG}#earthly-gradle-cache" | ||
IF [ "$GRADLE_USER_HOME" = "" ] | ||
ENV GRADLE_USER_HOME="$HOME/.gradle" | ||
END | ||
ENV EARTHLY_GRADLE_CACHE_PREFIX=$cache_prefix | ||
ENV EARTHLY_GRADLE_USER_HOME_CACHE="type=cache,mode=0777,id=$cache_prefix,sharing=shared,target=$GRADLE_USER_HOME" | ||
ENV EARTHLY_GRADLE_PROJECT_CACHE="type=cache,mode=0777,id=${cache_prefix}#project,sharing=shared,target=.gradle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# lib/gradle | ||
|
||
Earthly's official collection of Gradle [functions](https://docs.earthly.dev/docs/guides/functions). | ||
|
||
First, import the library up in your Earthfile: | ||
```earthfile | ||
VERSION --global-cache 0.7 | ||
IMPORT github.com/earthly/lib/gradle:<version/commit> AS gradle | ||
``` | ||
> :warning: Due to [this issue](https://github.com/earthly/earthly/issues/3490), make sure to enable `--global-cache` in the calling Earthfile, as shown above. | ||
## +GRADLE_GET_MOUNT_CACHE | ||
|
||
This function sets the following entries in the calling environment, so they can be used later to parametrize two global mount caches in `RUN` commands: | ||
- `$EARTHLY_GRADLE_USER_HOME_CACHE`: Code of the mount cache for the [gradle user home](https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home) directory. | ||
- `$EARTHLY_GRADLE_PROJECT_CACHE`: Code of the mount cache for the [gradle project root](https://docs.gradle.org/current/userguide/directory_layout.html#dir:project_root) directory. | ||
|
||
### Arguments | ||
- `cache_prefix`: To be used in both caches. By default: `${EARTHLY_TARGET_PROJECT_NO_TAG}#${OS_RELEASE}#earthly-gradle-cache` | ||
|
||
### Example | ||
```earthly | ||
DO gradle+GRADLE_GET_MOUNT_CACHE | ||
RUN --mount=$EARTHLY_GRADLE_USER_HOME_CACHE --mount=$EARTHLY_GRADLE_PROJECT_CACHE gradle --no-daemon build | ||
``` | ||
|
||
### Scoping | ||
|
||
If `cache_prefix` is not set, the two global caches have an Earthfile-scope, that is, they are not shared with other Earthfiles. | ||
Otherwise, all Earthfiles using the same `cache_prefix` will share the cache mounts. | ||
|
||
## Example | ||
See [earthly-intellij-plugin](https://github.com/earthly/earthly-intellij-plugin/blob/main/Earthfile) for a complete example. |