Add busybox wget support as fallback in only-mvnw script
- Enhanced only-mvnw script to try busybox wget when neither wget nor curl is available
- Added busybox wget detection in all HTTP request functions:
* resolve_jdk_url() for JDK URL resolution API calls
* redirect URL resolution logic
* get_latest_version_from_disco() for version API calls
* install_jdk() for JDK file downloads
* main Maven distribution download section
- Updated error messages to include busybox wget as supported option
- Updated integration tests to handle busybox wget error messages
- Improves compatibility with minimal Linux environments like Alpine containers
diff --git a/maven-wrapper-distribution/src/resources/only-mvnw b/maven-wrapper-distribution/src/resources/only-mvnw
index 4ac0a96..a547dda 100755
--- a/maven-wrapper-distribution/src/resources/only-mvnw
+++ b/maven-wrapper-distribution/src/resources/only-mvnw
@@ -196,8 +196,10 @@
_resolve_api_response="$(curl -s -f "$_resolve_disco_api_url" 2>/dev/null)"
elif command -v wget >/dev/null; then
_resolve_api_response="$(wget -q -O - "$_resolve_disco_api_url" 2>/dev/null)"
+ elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
+ _resolve_api_response="$(busybox wget -q -O - "$_resolve_disco_api_url" 2>/dev/null)"
else
- die "Cannot resolve JDK URL: curl or wget required"
+ die "Cannot resolve JDK URL: curl, wget, or busybox wget required"
fi
if [ -z "$_resolve_api_response" ]; then
@@ -216,6 +218,8 @@
_resolve_download_url="$(curl -s -I "$_resolve_redirect_url" 2>/dev/null | grep -i '^location:' | cut -d' ' -f2- | tr -d '\r\n')"
elif command -v wget >/dev/null; then
_resolve_download_url="$(wget -q -S -O /dev/null "$_resolve_redirect_url" 2>&1 | grep -i '^ location:' | cut -d' ' -f4- | tr -d '\r\n')"
+ elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
+ _resolve_download_url="$(busybox wget -q -S -O /dev/null "$_resolve_redirect_url" 2>&1 | grep -i '^ location:' | cut -d' ' -f4- | tr -d '\r\n')"
else
# Fallback to using the redirect URL directly
_resolve_download_url="$_resolve_redirect_url"
@@ -334,8 +338,10 @@
api_response="$(curl -s -f "$disco_api_url" 2>/dev/null)"
elif command -v wget >/dev/null; then
api_response="$(wget -q -O - "$disco_api_url" 2>/dev/null)"
+ elif command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
+ api_response="$(busybox wget -q -O - "$disco_api_url" 2>/dev/null)"
else
- verbose "No HTTP client (curl/wget) available for Disco API"
+ verbose "No HTTP client (curl/wget/busybox wget) available for Disco API"
return 1 # No HTTP client available
fi
@@ -508,8 +514,10 @@
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$url" -O "$jdk_file" || die "wget: Failed to fetch JDK from $url"
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$jdk_file" "$url" || die "curl: Failed to fetch JDK from $url"
+ elif [ -z "${MVNW_USERNAME-}" ] && command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
+ busybox wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$url" -O "$jdk_file" || die "busybox wget: Failed to fetch JDK from $url"
else
- die "Cannot download JDK: wget or curl required"
+ die "Cannot download JDK: wget, curl, or busybox wget required"
fi
# Verify checksum if provided
@@ -670,6 +678,9 @@
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
verbose "Found curl ... using curl"
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
+elif [ -z "${MVNW_USERNAME-}" ] && command -v busybox >/dev/null && busybox wget --help >/dev/null 2>&1; then
+ verbose "Found busybox wget ... using busybox wget"
+ busybox wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "busybox wget: Failed to fetch $distributionUrl"
elif set_java_home; then
verbose "Falling back to use Java to download"
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
diff --git a/maven-wrapper-plugin/src/it/projects/jdk_checksum_verification/verify.groovy b/maven-wrapper-plugin/src/it/projects/jdk_checksum_verification/verify.groovy
index 225b9df..64ed1a2 100644
--- a/maven-wrapper-plugin/src/it/projects/jdk_checksum_verification/verify.groovy
+++ b/maven-wrapper-plugin/src/it/projects/jdk_checksum_verification/verify.groovy
@@ -44,7 +44,7 @@
// 2. Network issues preventing download
// 3. System JDK usage (if JDK download is skipped)
boolean checksumFailure = log.contains("checksum") || log.contains("SHA-256") || log.contains("verification")
-boolean networkIssue = log.contains("Failed to fetch") || log.contains("curl:") || log.contains("wget:")
+boolean networkIssue = log.contains("Failed to fetch") || log.contains("curl:") || log.contains("wget:") || log.contains("busybox wget:")
// The test should either fail checksum verification or use system JDK
assert checksumFailure || networkIssue || systemJdkUsed, "Either checksum verification should occur, network issue encountered, or system JDK should be used"
diff --git a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy
index 8bcdfbf..c33f4b9 100644
--- a/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy
+++ b/maven-wrapper-plugin/src/it/projects/type_only-script-fail/verify.groovy
@@ -27,5 +27,5 @@
} else {
// on non-Windows: verify clear messages as well
// cover all methods: point is, there is no Maven version 0.0.0
- assert log.contains('wget: Failed to fetch') || log.contains('curl: Failed to fetch') || log.contains('- Error downloading:')
+ assert log.contains('wget: Failed to fetch') || log.contains('curl: Failed to fetch') || log.contains('busybox wget: Failed to fetch') || log.contains('- Error downloading:')
}