Files

61 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerates output/*.txt. Needs: G8 (Gradle 8.14.x), G9 (Gradle 9.x), J21 and J25 (JAVA_HOME dirs).
set -u
G8=${G8:-/opt/gradle/bin/gradle}; G9=${G9:-/tmp/tools/gradle-9.8.0/bin/gradle}
J21=${J21:-/usr/lib/jvm/java-21-openjdk-amd64}; J25=${J25:-/tmp/tools/jdk-25.0.4.1+1}
HERE=$(cd "$(dirname "$0")/.." && pwd); OUT=$HERE/output; W=${WORK:-/tmp/g9-work}
mkdir -p "$OUT"; rm -rf "$W"; mkdir -p "$W"
clean() { grep -v 'JAVA_TOOL_OPTIONS' | sed "s#$W#WORK#g; s#$HERE#REPO#g; s/ in [0-9msh ]*\$//; /^Daemon will be stopped/d; /^Starting a Gradle Daemon/d; /^See the complete report/d"; }
run() { # run <javahome> <dir> <gradle> args...
local jh=$1 d=$2 g=$3; shift 3; (cd "$d" && JAVA_HOME=$jh "$g" --console=plain "$@" 2>&1 | clean); }
fresh() { rm -rf "$W/$1"; cp -r "$HERE/before" "$W/$1"; rm -rf "$W/$1/build" "$W/$1/.gradle"; }
{ echo '$ gradle --version (Gradle 8)'; JAVA_HOME=$J21 $G8 --version 2>&1 | grep -E '^Gradle|^Launcher|^Kotlin|^Groovy'
echo; echo '$ gradle --version (Gradle 9)'; JAVA_HOME=$J25 $G9 --version 2>&1 | grep -E '^Gradle|^Launcher|^Kotlin|^Groovy'; } > "$OUT/00-environment.txt"
fresh a
{ echo '$ gradle build --warning-mode all # Gradle 8.14.3, JDK 21, legacy Groovy build'
run "$J21" "$W/a" "$G8" build --warning-mode all | grep -E 'deprecat|Deprecat|BUILD|build.gradle|Gradle 9|Gradle 10|Task.project' ; } > "$OUT/01-legacy-on-gradle8.txt"
fresh b
{ echo '$ gradle build # Gradle 9.8.0, JDK 25, same legacy build, unchanged'
run "$J25" "$W/b" "$G9" build | grep -E 'What went wrong|Could not|BUILD|build.gradle' ; } > "$OUT/02-legacy-on-gradle9-sourceCompatibility.txt"
fresh c
python3 - "$W/c/build.gradle" <<'PY'
import sys; p=sys.argv[1]; s=open(p).read()
s=s.replace("sourceCompatibility = '17'","java { sourceCompatibility = JavaVersion.VERSION_17 }"); open(p,'w').write(s)
PY
{ echo "\$ gradle build # after replacing sourceCompatibility = '17' with java { sourceCompatibility = ... }"
run "$J25" "$W/c" "$G9" build | grep -E 'What went wrong|Could not|BUILD|build.gradle' ; } > "$OUT/03-legacy-on-gradle9-archivesBaseName.txt"
fresh d
python3 - "$W/d/build.gradle" <<'PY'
import sys; p=sys.argv[1]; s=open(p).read()
s=s.replace("sourceCompatibility = '17'","java { sourceCompatibility = JavaVersion.VERSION_17 }")
s=s.replace("archivesBaseName = 'g9demo-legacy'","base { archivesName = 'g9demo-legacy' }"); open(p,'w').write(s)
PY
{ echo '$ gradle build buildInfo --warning-mode all # both removals fixed'
run "$J25" "$W/d" "$G9" build buildInfo --warning-mode all | grep -E 'deprecat|Deprecat|BUILD|Gradle 10|Task.project|build.gradle' ; } > "$OUT/04-legacy-fixed-on-gradle9.txt"
rm -rf "$W/d/build" "$W/d/.gradle"
{ echo '$ gradle buildInfo --configuration-cache # same fixed legacy build'
run "$J25" "$W/d" "$G9" buildInfo --configuration-cache | grep -E 'What went wrong|Task.project|BUILD|onfiguration cache|problem|build.gradle|FAILED' ; } > "$OUT/05-legacy-configuration-cache.txt"
rm -rf "$W/after"; cp -r "$HERE/after" "$W/after"; rm -rf "$W/after/build" "$W/after/.gradle"
{ echo '$ ./gradlew buildInfo test --configuration-cache # migrated build, first run'
run "$J25" "$W/after" "$W/after/gradlew" buildInfo test --configuration-cache | grep -E 'BUILD|onfiguration cache|Task :(buildInfo|test)'
echo; echo '$ ./gradlew buildInfo test --configuration-cache # second run'
run "$J25" "$W/after" "$W/after/gradlew" buildInfo test --configuration-cache | grep -E 'BUILD|onfiguration cache|Task :(buildInfo|test)'
echo; echo '$ BUILD_STAMP=ci42 ./gradlew buildInfo --configuration-cache # env var changed'
(cd "$W/after" && BUILD_STAMP=ci42 JAVA_HOME=$J25 ./gradlew --console=plain buildInfo --configuration-cache 2>&1 | clean | grep -E 'BUILD|onfiguration cache|input|BUILD_STAMP')
echo; echo '$ cat build/build-info.txt'; cat "$W/after/build/build-info.txt"; } > "$OUT/06-migrated-configuration-cache.txt"
{ echo '$ ./gradlew build # migrated build on the Gradle wrapper (9.8.0), tests included'
run "$J25" "$W/after" "$W/after/gradlew" clean build | grep -E 'BUILD|Task :(test|bootJar)|actionable'
echo; echo '$ ls build/libs'; ls "$W/after/build/libs"; } > "$OUT/07-migrated-build.txt"
{ echo '$ gradle build # Gradle 8.14.3 on JDK 25 (launcher JVM), migrated build'
(cd "$W/after" && JAVA_HOME=$J25 $G8 --console=plain build 2>&1 | clean | grep -vE '^$' | head -12); } > "$OUT/08-gradle8-on-jdk25.txt"
echo done