'Busybox wget to download jar fails with an error "wget: server returned error: HTTP/1.1 307 Temporary Redirect"

I am using adoptopenjdk/openjdk11:alpine-jre base image for java and trying below instruction inside my Dockerfile,

RUN wget -O dd-java-agent.jar "https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.datadoghq&a=dd-java-agent&v=LATEST"

which produces an error: Connecting to repository.sonatype.org (18.208.14.211:443) wget: server returned error: HTTP/1.1 307 Temporary Redirect

Is there a way to download the latest version of jar file from nexus using wget utility available with Busybox?

Alpine version: v3.12.0 | Busybox version: v1.31.1

Note: If I specify the exact version of jar like RUN wget -O dd-java-agent.jar 'https://repository.sonatype.org/service/local/repositories/central-proxy/content/com/datadoghq/dd-java-agent/0.38.0/dd-java-agent-0.38.0.jar' it succeeded. I am aware of other option is to use curl in this case. Just trying to keep it simple and avoiding the installation of curl, its usage, and then removal.



Solution 1:[1]

BusyBox replaces Wget with a compact implementation of its own, which does not support all the security features and options such as https redirects. Worse, the BusyBox TLS library does not support certificate validation nor the option --no-check-certificate. Issue discussed on Git https://github.com/sabotage-linux/sabotage/issues/252 6 years ago but actually never fixed.

There is no solution with busybox wget other then:

  • adding the real wget to your build
  • adding curl

Solution 2:[2]

Starting from BusyBox 1.34.0 (19 August 2021) the 307 and 308 redirects are supported. Commit e71ea6c1f84318d8655a5783736288695174f596

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 scavenger
Solution 2 Sergey Ponomarev