Skip to content

Commit b476f7f

Browse files
committed
feat: add jenv-gradle-low-ram skill for low-RAM Gradle builds
1 parent 4b8e77c commit b476f7f

File tree

1 file changed

+118
-0
lines changed
  • .github/skills/jenv-gradle-low-ram

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
name: jenv-gradle-low-ram
3+
description: 'Align jenv with .java-version and run Gradle reliably on low-RAM machines. Use for Java mismatch errors, Gradle OOMs, daemon memory pressure, and selecting safe build flags.'
4+
argument-hint: 'Describe your target task and available RAM, for example: assembleDebug on 8GB RAM'
5+
---
6+
# Jenv + Gradle Low-RAM Workflow
7+
8+
## What This Skill Produces
9+
10+
- A shell where `java` and Gradle use the Java version pinned by `.java-version`.
11+
- A repeatable Gradle command profile tuned for constrained memory.
12+
- Verification checks to confirm version alignment and build stability.
13+
14+
## When To Use
15+
16+
- Any time when `./gradlew` is about to be invoked in this repository.
17+
- Especially important for low-RAM machines where daemon/worker pressure can destabilize builds.
18+
- Required when verifying that Java from `.java-version` is the active runtime for Gradle.
19+
20+
## Procedure
21+
22+
1. Detect the required Java version.
23+
24+
```bash
25+
cat .java-version
26+
```
27+
28+
2. Verify `jenv` is installed and initialized.
29+
30+
```bash
31+
command -v jenv
32+
jenv versions
33+
jenv version
34+
```
35+
36+
Decision point:
37+
38+
- If `jenv` is not found, install and initialize it in your shell startup.
39+
- If `jenv` is found but `jenv version` does not match `.java-version`, continue to step 3.
40+
41+
3. Align local Java to the repository pin.
42+
43+
```bash
44+
required_java="$(cat .java-version)"
45+
jenv local "$required_java"
46+
```
47+
48+
Decision point:
49+
50+
- If `jenv local` fails because the version is missing, install that JDK and run `jenv add <jdk-path>`, then retry.
51+
52+
4. Confirm runtime alignment before any Gradle task.
53+
54+
```bash
55+
java -version
56+
./gradlew -version
57+
```
58+
59+
Quality check:
60+
61+
- Gradle JVM version in `./gradlew -version` must match `.java-version` major version.
62+
63+
5. Run Gradle with low-memory-safe defaults.
64+
65+
Preferred one-off profile:
66+
67+
```bash
68+
./gradlew --no-daemon --max-workers=2 \
69+
-Dorg.gradle.jvmargs="-Xmx1536m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
70+
assembleDebug
71+
```
72+
73+
For tests:
74+
75+
```bash
76+
./gradlew --no-daemon --max-workers=2 \
77+
-Dorg.gradle.jvmargs="-Xmx1792m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
78+
testDebugUnitTest
79+
```
80+
81+
6. If memory pressure continues, downgrade concurrency.
82+
83+
```bash
84+
./gradlew --no-daemon --max-workers=1 -Dorg.gradle.parallel=false assembleDebug
85+
```
86+
87+
7. If builds are stable and you want persistence, prefer user-local Gradle overrides (avoid committing repo-wide memory changes).
88+
89+
Suggested entries for `~/.gradle/gradle.properties`:
90+
91+
```properties
92+
org.gradle.daemon=false
93+
org.gradle.parallel=false
94+
org.gradle.workers.max=2
95+
org.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8
96+
```
97+
98+
## Troubleshooting Branches
99+
100+
- `jenv version` correct but `java -version` wrong:
101+
Ensure shell init runs `eval "$(jenv init -)"` and enable export plugin with `jenv enable-plugin export`.
102+
- `Gradle daemon disappeared unexpectedly`:
103+
Retry with `--no-daemon --max-workers=1` and lower `-Xmx` if the OS is reclaiming memory aggressively.
104+
- Kotlin compile OOM:
105+
Keep workers low, disable parallel, and run module-targeted tasks (for example `:feature:media:assembleDebug`) instead of full-project builds.
106+
107+
## Completion Checks
108+
109+
- `.java-version` and `jenv version` resolve to the same Java release.
110+
- `./gradlew -version` reports the expected JVM.
111+
- Target Gradle task completes without OOM or daemon crash.
112+
- Machine remains responsive during build (no prolonged swap thrash).
113+
114+
## Fast Invocation Examples
115+
116+
- "Align my shell to `.java-version` and run debug build with 8GB RAM settings"
117+
- "I get class file major version errors; fix jenv and verify Gradle JVM"
118+
- "Run unit tests with a low-memory Gradle profile and fallback if OOM occurs"

0 commit comments

Comments
 (0)