From cf1901b1adc4fe35fcafa3e8aafa769904e6cdcf Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 19 Nov 2026 12:03:58 -0800 Subject: [PATCH 1/3] Retry a Gradle run that fails to resolve a dependency Maven Central sometimes transiently returns 404 for an artifact that it holds. The new script .github/gradlew-retry.sh runs ./gradlew and, if Gradle could not resolve a dependency, waits and runs it once more with --refresh-dependencies (Gradle caches the absence of a module, so a plain retry fails the same way). Other failures are not retried. Also set fail-fast: false, so that one failing matrix job does not cancel the others. --- .github/gradlew-retry.sh | 26 ++++++++++++++++++++++++++ .github/workflows/gradle.yml | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100755 .github/gradlew-retry.sh diff --git a/.github/gradlew-retry.sh b/.github/gradlew-retry.sh new file mode 100755 index 000000000..339287961 --- /dev/null +++ b/.github/gradlew-retry.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Usage: .github/gradlew-retry.sh [GRADLE-ARGUMENT...] +# +# Run ./gradlew with the given arguments. If that fails because Gradle could not resolve a +# dependency, wait, then run ./gradlew once more with --refresh-dependencies. Exit with the status +# of the last run of ./gradlew. Other failures, such as a compilation error or a test failure, are +# not retried. +# +# A repository such as Maven Central sometimes transiently fails to serve an artifact that it +# holds, for example by returning 404. Gradle caches the result that a module is missing and does +# not query the repositories for that module again until the cache entry expires, so a retry +# without --refresh-dependencies would fail the same way. + +set -o pipefail + +log=$(mktemp) +./gradlew "$@" 2>&1 | tee "$log" +status=$? +if [ "$status" -eq 0 ] || ! grep -qE 'Could not resolve all |Plugin \[id: .*\] was not found' "$log"; then + exit "$status" +fi + +echo "gradlew-retry.sh: Gradle could not resolve a dependency; retrying in 60 seconds." +sleep 60 +exec ./gradlew --refresh-dependencies "$@" diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2337b5643..c4a2c1f9a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -24,13 +24,14 @@ jobs: check-latest: true cache: 'gradle' - name: ./gradlew spotlessCheck - run: ./gradlew spotlessCheck + run: .github/gradlew-retry.sh spotlessCheck build: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: java: ['21', '25', '27-ea'] include: @@ -69,4 +70,4 @@ jobs: # they are in the tool cache rather than in a standard location. # The "spotless" job above performs the formatting checks. - name: ./gradlew build - run: _JAVA_OPTIONS=-Xmx2g ./gradlew build -x spotlessCheck -PtestJavaVersion=${{ matrix.javaMajor }} -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.javaMajor }}_${{ runner.arch }},JAVA_HOME_21_${{ runner.arch }} + run: _JAVA_OPTIONS=-Xmx2g .github/gradlew-retry.sh build -x spotlessCheck -PtestJavaVersion=${{ matrix.javaMajor }} -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.javaMajor }}_${{ runner.arch }},JAVA_HOME_21_${{ runner.arch }} From e90ed189020088ffea809411de190bf86cc40841 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 19 Nov 2026 12:21:04 -0800 Subject: [PATCH 2/3] gradlew-retry.sh: retry twice, and skip a 404 for a nonexistent artifact Gradle does not cache a 404 across runs, so --refresh-dependencies is unnecessary; drop it. A transient 404 from Maven Central can last a minute or more, so retry up to twice, after 60 and then 180 seconds. To avoid pointless retries when a dependency does not exist, retry a 404 only if the artifact exists at the URL that Gradle reported or on a mirror of Maven Central. --- .github/gradlew-retry.sh | 76 ++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/.github/gradlew-retry.sh b/.github/gradlew-retry.sh index 339287961..50b2ece21 100755 --- a/.github/gradlew-retry.sh +++ b/.github/gradlew-retry.sh @@ -3,24 +3,72 @@ # Usage: .github/gradlew-retry.sh [GRADLE-ARGUMENT...] # # Run ./gradlew with the given arguments. If that fails because Gradle could not resolve a -# dependency, wait, then run ./gradlew once more with --refresh-dependencies. Exit with the status -# of the last run of ./gradlew. Other failures, such as a compilation error or a test failure, are -# not retried. +# dependency that a retry might resolve, wait, then run ./gradlew again, up to 2 more times. Exit +# with the status of the last run of ./gradlew. Other failures, such as a compilation error or a +# test failure, are not retried. # # A repository such as Maven Central sometimes transiently fails to serve an artifact that it -# holds, for example by returning 404. Gradle caches the result that a module is missing and does -# not query the repositories for that module again until the cache entry expires, so a retry -# without --refresh-dependencies would fail the same way. +# holds, for example by returning 404 for a minute or more. A dependency that does not exist, such +# as a mistyped version, also yields 404; to avoid pointless retries in that case, this script +# retries a 404 only if the artifact exists, according to the URL where Gradle looked for it or a +# Google-hosted mirror of Maven Central. This script consults the mirror only to make that +# decision; Gradle never downloads from it. set -o pipefail +# The prefix of each Maven Central URL that Gradle reports, and the corresponding prefix on the +# mirror. +central=https://repo.maven.apache.org/maven2/ +mirror=https://maven-central.storage-download.googleapis.com/maven2/ + log=$(mktemp) -./gradlew "$@" 2>&1 | tee "$log" -status=$? -if [ "$status" -eq 0 ] || ! grep -qE 'Could not resolve all |Plugin \[id: .*\] was not found' "$log"; then - exit "$status" -fi -echo "gradlew-retry.sh: Gradle could not resolve a dependency; retrying in 60 seconds." -sleep 60 -exec ./gradlew --refresh-dependencies "$@" +# Return 0 (true) if the given URL serves a file. +url_exists() { + curl --silent --fail --head --location --max-time 20 --output /dev/null "$1" +} + +# Return 0 (true) if the run of Gradle that wrote $log failed in a way that a retry might fix. +retry_might_help() { + if ! grep -qE 'Could not resolve all |Plugin \[id: .*\] was not found' "$log"; then + return 1 + fi + # Gradle lists the URLs at which it did not find a module, one per line, as in + # " - https://repo.maven.apache.org/maven2/org/example/x/1.0/x-1.0.pom". + local urls + urls=$(sed -n 's/^ *- \(https:\/\/[^ ]*\)$/\1/p' "$log" | sort -u) + # A failure other than a 404, such as a timeout or a 5xx status, does not list URLs. + if [ -z "$urls" ] || grep -qE 'Could not (GET|HEAD) ' "$log"; then + return 0 + fi + local url + for url in $urls; do + if url_exists "$url"; then + echo "gradlew-retry.sh: $url exists." + return 0 + fi + case "$url" in + "$central"*) + if url_exists "$mirror${url#"$central"}"; then + echo "gradlew-retry.sh: $url exists on a mirror of Maven Central." + return 0 + fi + ;; + esac + done + echo "gradlew-retry.sh: Not retrying, because no missing artifact exists at a URL that Gradle" + echo " reported or on a mirror of Maven Central." + return 1 +} + +# The number of seconds to wait before each retry. +for delay in 60 180; do + ./gradlew "$@" 2>&1 | tee "$log" + status=$? + if [ "$status" -eq 0 ] || ! retry_might_help; then + exit "$status" + fi + echo "gradlew-retry.sh: Gradle could not resolve a dependency; retrying in $delay seconds." + sleep "$delay" +done +exec ./gradlew "$@" From a4d2081c0f5548e21fbf8865560e5bd6c2f6b77a Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 19 Nov 2026 12:37:44 -0800 Subject: [PATCH 3/3] Use gradlew-retry from plume-scripts rather than a copy in this repository CI clones plume-lib/plume-scripts and runs the Gradle commands through its gradlew-retry script, so that the script is not duplicated in every plume-lib repository. --- .github/gradlew-retry.sh | 74 ------------------------------------ .github/workflows/gradle.yml | 8 +++- 2 files changed, 6 insertions(+), 76 deletions(-) delete mode 100755 .github/gradlew-retry.sh diff --git a/.github/gradlew-retry.sh b/.github/gradlew-retry.sh deleted file mode 100755 index 50b2ece21..000000000 --- a/.github/gradlew-retry.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# Usage: .github/gradlew-retry.sh [GRADLE-ARGUMENT...] -# -# Run ./gradlew with the given arguments. If that fails because Gradle could not resolve a -# dependency that a retry might resolve, wait, then run ./gradlew again, up to 2 more times. Exit -# with the status of the last run of ./gradlew. Other failures, such as a compilation error or a -# test failure, are not retried. -# -# A repository such as Maven Central sometimes transiently fails to serve an artifact that it -# holds, for example by returning 404 for a minute or more. A dependency that does not exist, such -# as a mistyped version, also yields 404; to avoid pointless retries in that case, this script -# retries a 404 only if the artifact exists, according to the URL where Gradle looked for it or a -# Google-hosted mirror of Maven Central. This script consults the mirror only to make that -# decision; Gradle never downloads from it. - -set -o pipefail - -# The prefix of each Maven Central URL that Gradle reports, and the corresponding prefix on the -# mirror. -central=https://repo.maven.apache.org/maven2/ -mirror=https://maven-central.storage-download.googleapis.com/maven2/ - -log=$(mktemp) - -# Return 0 (true) if the given URL serves a file. -url_exists() { - curl --silent --fail --head --location --max-time 20 --output /dev/null "$1" -} - -# Return 0 (true) if the run of Gradle that wrote $log failed in a way that a retry might fix. -retry_might_help() { - if ! grep -qE 'Could not resolve all |Plugin \[id: .*\] was not found' "$log"; then - return 1 - fi - # Gradle lists the URLs at which it did not find a module, one per line, as in - # " - https://repo.maven.apache.org/maven2/org/example/x/1.0/x-1.0.pom". - local urls - urls=$(sed -n 's/^ *- \(https:\/\/[^ ]*\)$/\1/p' "$log" | sort -u) - # A failure other than a 404, such as a timeout or a 5xx status, does not list URLs. - if [ -z "$urls" ] || grep -qE 'Could not (GET|HEAD) ' "$log"; then - return 0 - fi - local url - for url in $urls; do - if url_exists "$url"; then - echo "gradlew-retry.sh: $url exists." - return 0 - fi - case "$url" in - "$central"*) - if url_exists "$mirror${url#"$central"}"; then - echo "gradlew-retry.sh: $url exists on a mirror of Maven Central." - return 0 - fi - ;; - esac - done - echo "gradlew-retry.sh: Not retrying, because no missing artifact exists at a URL that Gradle" - echo " reported or on a mirror of Maven Central." - return 1 -} - -# The number of seconds to wait before each retry. -for delay in 60 180; do - ./gradlew "$@" 2>&1 | tee "$log" - status=$? - if [ "$status" -eq 0 ] || ! retry_might_help; then - exit "$status" - fi - echo "gradlew-retry.sh: Gradle could not resolve a dependency; retrying in $delay seconds." - sleep "$delay" -done -exec ./gradlew "$@" diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c4a2c1f9a..d0b5a1715 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -23,8 +23,10 @@ jobs: java-version: '25' check-latest: true cache: 'gradle' + - name: Clone plume-scripts + run: git clone --depth 1 -q https://github.com/plume-lib/plume-scripts.git "${{ runner.temp }}/plume-scripts" - name: ./gradlew spotlessCheck - run: .github/gradlew-retry.sh spotlessCheck + run: ${{ runner.temp }}/plume-scripts/gradlew-retry spotlessCheck build: @@ -66,8 +68,10 @@ jobs: java -version echo 'JVM that runs the tests:' "$JAVA_HOME_${{ matrix.javaMajor }}_${{ runner.arch }}/bin/java" -version + - name: Clone plume-scripts + run: git clone --depth 1 -q https://github.com/plume-lib/plume-scripts.git "${{ runner.temp }}/plume-scripts" # Gradle does not auto-detect the JDKs that "setup-java" installs, because # they are in the tool cache rather than in a standard location. # The "spotless" job above performs the formatting checks. - name: ./gradlew build - run: _JAVA_OPTIONS=-Xmx2g .github/gradlew-retry.sh build -x spotlessCheck -PtestJavaVersion=${{ matrix.javaMajor }} -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.javaMajor }}_${{ runner.arch }},JAVA_HOME_21_${{ runner.arch }} + run: _JAVA_OPTIONS=-Xmx2g ${{ runner.temp }}/plume-scripts/gradlew-retry build -x spotlessCheck -PtestJavaVersion=${{ matrix.javaMajor }} -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.javaMajor }}_${{ runner.arch }},JAVA_HOME_21_${{ runner.arch }}