Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
96 changes: 96 additions & 0 deletions bin/update-gradle-wrappers
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash

set -euo pipefail

# Update Gradle wrappers across all exercises.
# Usage:
# bin/update-gradle-wrappers [<gradle-version>]
# Example:
# bin/update-gradle-wrappers 9.2.1

DEFAULT_VERSION="9.2.1"
VERSION="${1:-$DEFAULT_VERSION}"

# ANSI Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

log() { printf "${GREEN}[update-wrappers]${NC} %s\n" "$*"; }
warn() { printf "${YELLOW}[update-wrappers][WARN]${NC} %s\n" "$*"; }
err() { printf "${RED}[update-wrappers][ERROR]${NC} %s\n" "$*" >&2; }
die() { printf "${RED}[update-wrappers][FATAL]${NC} %s\n" "$*" >&2; exit 1; }

# Resolve repo root (works whether run from repo root or any subdir)
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
if REPO_ROOT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then
:
else
# Fallback: assume script is in <repo>/bin
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
fi

EXERCISES_DIR="$REPO_ROOT/exercises"
CONCEPT_DIR="$EXERCISES_DIR/concept"
PRACTICE_DIR="$EXERCISES_DIR/practice"
SHARED_WRAPPER_DIR="$EXERCISES_DIR/gradle/wrapper"

if [[ ! -d "$EXERCISES_DIR" ]]; then
err "Cannot find exercises directory at $EXERCISES_DIR"
exit 1
fi

# 1. Update the 'Seed' wrapper
# We assume the root 'exercises' directory is the master Gradle project
SEED_DIR="$EXERCISES_DIR"
SEED_WRAPPER_DIR="$SEED_DIR/gradle/wrapper"
SEED_JAR="$SEED_WRAPPER_DIR/gradle-wrapper.jar"
SEED_PROPS="$SEED_WRAPPER_DIR/gradle-wrapper.properties"

log "Targeting Gradle version: $VERSION"
log "Updating Master/Seed wrapper in: $SEED_DIR"

if [[ ! -d "$SEED_DIR" ]]; then
die "Seed directory not found: $SEED_DIR"
fi

if [[ ! -x "$SEED_DIR/gradlew" ]]; then
# Try to fix permissions if it exists but isn't executable
if [[ -f "$SEED_DIR/gradlew" ]]; then
warn "fix permissions for $SEED_DIR/gradlew"
chmod +x "$SEED_DIR/gradlew"
else
die "Seed does not contain a gradlew script: $SEED_DIR/gradlew"
fi
fi

log "Using seed: $SEED_DIR"

(
cd "$SEED_DIR"
log "Running: ./gradlew wrapper --gradle-version $VERSION"
./gradlew --no-daemon wrapper --gradle-version "$VERSION" || die "Gradle wrapper task failed in $SEED_DIR"
)

if [[ ! -f "$SEED_JAR" || ! -f "$SEED_PROPS" ]]; then
die "Seed wrapper files not found at $SEED_WRAPPER_DIR"
fi

# Distribute seed wrapper files to all exercises (simplified)
UPDATED_COUNT=0
for path in "$CONCEPT_DIR"/*/ "$PRACTICE_DIR"/*/; do
[[ -d "$path" ]] || continue
mkdir -p "$path/gradle/wrapper"
cp -f "$SEED_JAR" "$path/gradle/wrapper/gradle-wrapper.jar"
cp -f "$SEED_PROPS" "$path/gradle/wrapper/gradle-wrapper.properties"
cp -f "$SEED_DIR/gradlew" "$path/gradlew"
cp -f "$SEED_DIR/gradlew.bat" "$path/gradlew.bat"
chmod +x "$path/gradlew"
log "Updated wrapper files in: $path"
((UPDATED_COUNT++))
done

log "Done. Updated: $UPDATED_COUNT"

log "Reminder: wrappers also updated at $SHARED_WRAPPER_DIR"
52 changes: 52 additions & 0 deletions docs/update-gradle-wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Update Gradle Wrappers Across All Exercises

This repository contains many independent Gradle projects (one per exercise).
To update all Gradle wrappers to a specific version (e.g., to support Java 25), use the helper script below.

## Script name

Suggested name: `update-gradle-wrappers` (added under `bin/`).

## Requirements

- macOS/Linux shell with Bash
- Internet access (the first update will download the target Gradle distribution)

## Usage

```shell
bin/update-gradle-wrappers [<gradle-version>]
```

- If omitted, the version defaults to `9.2.1`.
- Example: update everything to Gradle 9.2.1

```shell
bin/update-gradle-wrappers 9.2.1
```

## What the script does

1. Uses the fixed seed at `exercises/gradle` and runs:

```shell
./gradlew wrapper --gradle-version <version>
```

This produces the correct `gradle-wrapper.jar` and `gradle-wrapper.properties` for the requested version.
2. Copies the wrapper files from the seed to every exercise’s `gradle/wrapper/` directory

This aligns with the requested approach: update via Gradle, and ensure consistency by copying the wrapper files everywhere.

## Notes

- The script uses `exercises/gradle` as the single source of truth (seed) and does not run Gradle in each exercise; it only copies the wrapper files.
- The operation can take time on the first run due to Gradle downloads.

## Troubleshooting

- If you see permission issues, make the script executable:

```shell
chmod +x bin/update-gradle-wrappers
```
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 7 additions & 8 deletions exercises/concept/annalyns-infiltration/gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -170,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )

JAVACMD=$( cygpath --unix "$JAVACMD" )

Expand Down Expand Up @@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
5 changes: 3 additions & 2 deletions exercises/concept/annalyns-infiltration/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -68,11 +70,10 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Binary file modified exercises/concept/bird-watcher/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 7 additions & 8 deletions exercises/concept/bird-watcher/gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -170,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )

JAVACMD=$( cygpath --unix "$JAVACMD" )

Expand Down Expand Up @@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
5 changes: 3 additions & 2 deletions exercises/concept/bird-watcher/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -68,11 +70,10 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading