Run Gradle tasks with minimal, high-signal output by capturing full logs and returning short summaries. Use when building, testing, or debugging Gradle projects.
Run Gradle in a way that minimizes token usage while preserving the signal needed to debug failures.
./gradlew -q --console=plain --warning-mode=none <task> > gradle.log 2>&1
Prefer:
./gradlew -q --console=plain --warning-mode=none :app:test --tests "com.example.MyTest" > gradle.log 2>&1
./gradlew -q --console=plain --warning-mode=none :service:compileJava > gradle.log 2>&1
Avoid broad commands unless necessary:
./gradlew build
./gradlew test
./gradlew check
#!/usr/bin/env bash
set -euo pipefail
LOG_DIR=".agent-logs"
LOG_FILE="$LOG_DIR/gradle.log"
mkdir -p "$LOG_DIR"
set +e
./gradlew -q --console=plain --warning-mode=none "$@" >"$LOG_FILE" 2>&1
EXIT_CODE=$?
set -e
echo "Exit code: $EXIT_CODE"
if [ "$EXIT_CODE" -eq 0 ]; then
echo "Status: SUCCESS"
grep -E "^(BUILD SUCCESSFUL|[0-9]+ actionable tasks:)" "$LOG_FILE" | tail -n 2 || true
exit 0
fi
echo "Status: FAILURE"
grep -E "^Execution failed for task " "$LOG_FILE" | head -n 10 || true
echo
tail -n 80 "$LOG_FILE"
echo
echo "Full log: $LOG_FILE"
exit "$EXIT_CODE"
Exit code: 0
Status: SUCCESS
BUILD SUCCESSFUL in 4s
6 actionable tasks: 2 executed, 4 up-to-date
Exit code: 1
Status: FAILURE
Execution failed for task ':app:test'.
...last 80 lines...
Full log: .agent-logs/gradle.log
build/test-results/test/
build/reports/tests/test/
build/reports/problems/
--info, --debug, or --stacktrace by defaultbuild repeatedly during tight loopsCapture everything, return only the minimum needed to decide the next step.