Background context
I use Nexus Repository Manager 3 to create raw proxy mirrors of software on premise for more stable build processes. Right now, I’m able to mirror all gradle and maven dependencies through Nexus. However, gradle wrapper still attempts to bootstrap gradle by downloading Gradle from the internet.
This topic has been discussed before Gradle Wrapper distributionUrl
Feature idea
I have an idea which I think would make this more desirable to the developers who would want to keep gradle wrapper simple.
Nexus and other mirrors typically support the same URL structure for distributionURL. The only difference is the domain where the files are hosted. It would be nice if one could set a GRADLE_DISTRIBUTION_MIRROR
environment variable. Then, instead of attempting to download from the distributionURL
defined in gradle/wrapper/gradle-wrapper.properties
it would substitute the beginning of the URL with the GRADLE_DISTRIBUTION_MIRROR.
Here’s the download URL differences:
- Before: https://services.gradle.org/distributions/gradle-4.1-bin.zip
- After: https://mirror.example.com/distributions/gradle-4.1-bin.zip
A groovy example of how this could work in gradle wrapper:
import java.util.regex.Pattern
String distributionUrl = 'https://services.gradle.org/distributions/gradle-4.1-bin.zip'
String distribution_mirror = System.getenv('GRADLE_DISTRIBUTION_MIRROR')
Pattern regex = Pattern.compile('^https?://[^/]+')
if(distribution_mirror) {
//will remove trailing slash defined by the user in the distribution_mirror
distributionUrl = regex.matcher(distributionUrl).replaceFirst(distribution_mirror -~ '/$')
}
//downloads from the mirror now
What are Gradle Wrapper devs’ thoughts?
Additional community benefits:
- AWS scenario: AWS charges for transfer costs so if a build process occurs in AWS one can proxy their hosted dependencies to save on these costs through repetitive downloads of Gradle.
- This would help reduce load on services.gradle.org by supporting a mirror. Heavy users of gradle wrapper (think entire companies) can download cached versions of Gradle instead of causing stress and load on gradle.org hosting.