Add offline Gradle build scripts for macOS

- build.sh scripts prioritize ~/.gradle/gradle-8.5/bin/gradle
- New build_all.sh orchestrates generic-client and sageclient builds
- sageclient build includes JDK 17/21 auto-detection
- Avoids network timeouts from services.gradle.org
This commit is contained in:
yumoqing 2026-05-21 18:01:20 +08:00
parent fe6261598b
commit 759b0585a8
3 changed files with 264 additions and 78 deletions

94
test/build_all.sh Executable file
View File

@ -0,0 +1,94 @@
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────
# bricks-mp — Build all test clients (generic-client, sageclient)
#
# Usage:
# ./build_all.sh # Build all
# ./build_all.sh generic # Build generic-client only
# ./build_all.sh sage # Build sageclient only
# ./build_all.sh run # Run generic-client
# ./build_all.sh clean # Clean all
# ──────────────────────────────────────────────────────────────
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
# ─── Find Gradle ───
find_gradle() {
if [ -x "$HOME/.gradle/gradle-8.5/bin/gradle" ]; then
echo "$HOME/.gradle/gradle-8.5/bin/gradle"
return 0
fi
if [ -x "$SCRIPT_DIR/../gradlew" ]; then
echo "$SCRIPT_DIR/../gradlew"
return 0
fi
if command -v gradle >/dev/null 2>&1; then
echo "gradle"
return 0
fi
return 1
}
if ! GRADLE_CMD="$(find_gradle)"; then
echo "ERROR: Gradle not found. Place at ~/.gradle/gradle-8.5 or install system gradle." >&2
exit 1
fi
echo "Using Gradle: $GRADLE_CMD"
MODE="${1:-build}"
gradle_build() {
local client="$1"
local dir="$SCRIPT_DIR/$client"
if [ ! -d "$dir" ]; then
echo "SKIP: $client (directory not found)"
return 0
fi
echo ""
echo "══════════════════════════════════════════════"
echo " Building: $client"
echo "══════════════════════════════════════════════"
cd "$dir"
case "$MODE" in
build|*)
"$GRADLE_CMD" compileKotlinJvm --no-daemon --no-configuration-cache
;;
run)
"$GRADLE_CMD" run --no-daemon --no-configuration-cache
;;
clean)
"$GRADLE_CMD" clean --no-daemon --no-configuration-cache
;;
package)
"$GRADLE_CMD" createDistributable --no-daemon --no-configuration-cache
;;
esac
echo "OK: $client"
}
case "$MODE" in
generic)
gradle_build generic-client
;;
sage)
gradle_build sageclient
;;
clean)
gradle_build generic-client
gradle_build sageclient
;;
run)
gradle_build generic-client
;;
build|*)
gradle_build generic-client
gradle_build sageclient
echo ""
echo "══════════════════════════════════════════════"
echo " All builds completed"
echo "══════════════════════════════════════════════"
;;
esac

View File

@ -1,36 +1,99 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
MODE="${1:-run}"
# ─── Gradle resolution ───
# 1. Local Gradle at ~/.gradle/gradle-8.5
# 2. Root project gradlew (with local dist cache)
# 3. System gradle command
find_gradle() {
local candidate
# Priority 1: User-provided local Gradle
if [ -x "$HOME/.gradle/gradle-8.5/bin/gradle" ]; then
echo "$HOME/.gradle/gradle-8.5/bin/gradle"
return 0
fi
# Priority 2: Root project gradlew (may use cached distribution)
if [ -x "$ROOT_DIR/gradlew" ]; then
echo "$ROOT_DIR/gradlew"
return 0
fi
# Priority 3: System gradle
if command -v gradle >/dev/null 2>&1; then
echo "gradle"
return 0
fi
return 1
}
if ! GRADLE_CMD="$(find_gradle)"; then
cat >&2 <<'EOF'
ERROR: Gradle not found.
Options:
1. Place Gradle at ~/.gradle/gradle-8.5/
2. Ensure the project root has gradlew
3. Install Gradle: brew install gradle
EOF
exit 1
fi
echo "Using Gradle: $GRADLE_CMD"
# ─── JDK check ───
java_major_version() {
local java_bin="$1"
local version_line
version_line="$($java_bin -version 2>&1 | head -n 1)"
printf '%s\n' "$version_line" | sed -E 's/.*version "([0-9]+)(\.[0-9]+)?.*/\1/'
}
if command -v java >/dev/null 2>&1; then
JAVA_VERSION="$(java_major_version java)"
if [[ "$JAVA_VERSION" =~ ^[0-9]+$ ]] && { [ "$JAVA_VERSION" -lt 17 ] || [ "$JAVA_VERSION" -gt 21 ]; }; then
cat >&2 <<EOF
WARNING: Java $JAVA_VERSION detected. This project requires JDK 17-21.
If build fails, install JDK 21 and set JAVA_HOME.
EOF
fi
fi
cd "$PROJECT_DIR"
MODE="${1:-build}"
case "$MODE" in
run)
echo "=== Building and running generic-client ==="
./gradlew run --no-daemon
"$GRADLE_CMD" run --no-daemon --no-configuration-cache
;;
build)
echo "=== Building generic-client ==="
./gradlew createDistributable --no-daemon
echo "Output: build/compose/binaries/main/"
"$GRADLE_CMD" compileKotlinJvm --no-daemon --no-configuration-cache
echo "Build OK. Use 'run' to launch, or 'package' for distributable."
;;
package)
echo "=== Packaging generic-client ==="
./gradlew packageDmg --no-daemon 2>/dev/null || \
./gradlew packageDeb --no-daemon 2>/dev/null || \
./gradlew packageMsi --no-daemon 2>/dev/null || \
echo "Note: Packaging requires the target OS (macOS/Windows/Linux)"
"$GRADLE_CMD" createDistributable --no-daemon --no-configuration-cache 2>/dev/null || \
"$GRADLE_CMD" packageDmg --no-daemon --no-configuration-cache 2>/dev/null || \
echo "Note: Packaging requires the target OS native environment"
;;
clean)
echo "=== Cleaning ==="
./gradlew clean --no-daemon
"$GRADLE_CMD" clean --no-daemon --no-configuration-cache
;;
*)
echo "Usage: $0 {run|build|package|clean}"
echo " run - Build and run the app (default)"
echo " build - Create distributable app bundle"
echo " package - Create OS-specific installer (dmg/deb/msi)"
echo " run - Build and run the app (default: build)"
echo " build - Compile only (default)"
echo " package - Create distributable app bundle"
echo " clean - Clean build artifacts"
exit 1
;;

View File

@ -5,6 +5,7 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
# ─── JDK resolution ───
java_major_version() {
local java_bin="$1"
local version_line
@ -97,17 +98,45 @@ EOF
exit 1
fi
# ─── Gradle resolution ───
# 1. Local Gradle at ~/.gradle/gradle-8.5
# 2. Root project gradlew
# 3. System gradle command
find_gradle() {
# Priority 1: User-provided local Gradle
if [ -x "$HOME/.gradle/gradle-8.5/bin/gradle" ]; then
echo "$HOME/.gradle/gradle-8.5/bin/gradle"
return 0
fi
# Priority 2: Root project gradlew
if [ -x "$ROOT_DIR/gradlew" ]; then
GRADLE_CMD=("$ROOT_DIR/gradlew")
elif command -v gradle >/dev/null 2>&1; then
GRADLE_CMD=(gradle)
else
echo "$ROOT_DIR/gradlew"
return 0
fi
# Priority 3: System gradle
if command -v gradle >/dev/null 2>&1; then
echo "gradle"
return 0
fi
return 1
}
if ! GRADLE_CMD="$(find_gradle)"; then
cat >&2 <<'EOF'
ERROR: Neither root gradlew nor system gradle was found.
Run from a checkout that contains the Gradle wrapper, or install Gradle.
ERROR: Neither local Gradle, root gradlew, nor system gradle was found.
Options:
1. Place Gradle 8.5 at ~/.gradle/gradle-8.5/
2. Ensure the project root has gradlew
3. Install Gradle: brew install gradle
EOF
exit 1
fi
echo "Using Gradle: $GRADLE_CMD"
cd "$PROJECT_DIR"
"${GRADLE_CMD[@]}" --no-configuration-cache build "$@"
"$GRADLE_CMD" --no-configuration-cache build "$@"