#!/usr/bin/env bash # What a Maven cache is worth: the same build against an empty and a populated local repository. source "$(dirname "$0")/lib.sh" REPO="${COLD_REPO:-/tmp/m2-cold-demo}" rm -rf "$REPO" run() { # label local start end n start=$(date +%s) mvn -B -Dmaven.repo.local="$REPO" -DskipITs verify > /tmp/cache-run.log 2>&1 || { tail -20 /tmp/cache-run.log; exit 1; } end=$(date +%s) n=$(grep -c 'Downloaded from' /tmp/cache-run.log || true) printf '%-34s downloads: %-5s seconds: %s\n' "$1" "$n" "$((end-start))" } { banner "mvn verify -DskipITs, local repository = $REPO" run "cold (empty local repository)" run "warm (repository restored)" printf 'local repository size after the run: %s\n' "$(du -sh "$REPO" | cut -f1)" echo "(seconds depend on the network; the download counts are the point)" } 2>&1 | tee "$OUT/02-cold-vs-warm-cache.txt"