# Support for gradle wrapper distribution mirror

**URL:** <https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838>\
**Category:** Help/Discuss\
**Created:** [May 6, 2018, 8:31pm UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838 "2018-05-06T20:31:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![samrocketman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/samrocketman/32/362_2.png) [@samrocketman](https://discuss.gradle.org/u/samrocketman)\
**Post date:** [May 6, 2018, 8:31pm UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/1 "2018-05-06T20:31:22Z")

</div>

# Background context

I use [Nexus Repository Manager 3 to create raw proxy](https://help.sonatype.com/repomanager3/raw-repositories-and-maven-sites#RawRepositoriesandMavenSites-ProxyingandGroupingRawRepositories) 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](https://discuss.gradle.org/t/gradle-wrapper-distributionurl/7116)

# 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](https://services.gradle.org/distributions/gradle-4.1-bin.zip)
- After: [https://mirror.example.com/distributions/gradle-4.1-bin.zip](https://mirror.example.com/distributions/gradle-4.1-bin.zip)

A groovy example of how this could work in gradle wrapper:

```gradle
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](http://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](http://gradle.org) hosting.

---

<div class="post-metadata">

**Author:** ![ddimitrov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ddimitrov/32/141_2.png) [@ddimitrov](https://discuss.gradle.org/u/ddimitrov)\
**Post date:** [May 7, 2018, 8:39am UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/2 "2018-05-07T08:39:29Z")

</div>

You may also check this thread: [Gradle wrapper in environments that require controlled builds](https://discuss.gradle.org/t/gradle-wrapper-in-environments-that-require-controlled-builds/11848)

Soon I’ll be on this topic again and will likely fork the Gradle Wrapper to a separate project (tentative name gradle-wrapper-plus). The result would be drop-in compatible JAR that you can use in place of the standard Gradle Wrapper jar and get some extra control over the download URL. I’ll post more when I have something.

---

<div class="post-metadata">

**Author:** ![Cinderhaze](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@Cinderhaze](https://discuss.gradle.org/u/Cinderhaze)\
**Post date:** [July 13, 2018, 1:57pm UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/3 "2018-07-13T13:57:20Z")

</div>

> [@ddimitrov](#):
>
> gradle-wrapper-plus

Have you had a chance to break that out into it’s own tool/repo?

---

<div class="post-metadata">

**Author:** ![ddimitrov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ddimitrov/32/141_2.png) [@ddimitrov](https://discuss.gradle.org/u/ddimitrov)\
**Post date:** [July 20, 2018, 2:08pm UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/4 "2018-07-20T14:08:48Z")

</div>

Sorry… Turns out I cannot open this - need to do a clean room which will probably wait…

---

<div class="post-metadata">

**Author:** ![samrocketman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/samrocketman/32/362_2.png) [@samrocketman](https://discuss.gradle.org/u/samrocketman)\
**Post date:** [August 13, 2018, 12:51am UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/5 "2018-08-13T00:51:10Z")

</div>

I have opened a small pull request which is basically what was originally proposed in this forum discussion [https://github.com/gradle/gradle/pull/6349](https://github.com/gradle/gradle/pull/6349)

---

<div class="post-metadata">

**Author:** ![DJViking](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@DJViking](https://discuss.gradle.org/u/DJViking)\
**Post date:** [August 15, 2018, 9:19am UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/6 "2018-08-15T09:19:58Z")

</div>

I am not a supporter to checking in files that can be generated  
gradle/wrapper/gradle-wrapper.jar  
gradle/wrapper/gradle-wrapper.properties  
gradlew  
gradlew.bat

Therefore the best solution would be to specify the distributionUrl within the global gradle.properties would work best. Then generating the gradle wrapper files would use that URL.

---

<div class="post-metadata">

**Author:** ![samrocketman](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/samrocketman/32/362_2.png) [@samrocketman](https://discuss.gradle.org/u/samrocketman)\
**Post date:** [August 17, 2018, 4:30am UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/7 "2018-08-17T04:30:01Z")

</div>

This makes an assumption that all projects build with the same version of gradle. This is not really a good assumption to make in a large environment with diverse Gradle projects.

Regarding files that can be generated. I respectfully disagree. The whole point of gradle wrapper is to self bootstrap gradle. If you don’t check in the gradle wrapper files and you need gradle to run gradle wrapper to generate the files, then that defeats the whole purpose of having gradle wrapper.

Back to the core of the subject this forum post, is about having an option to set a distribution mirror where alternative downloads of the same version of gradle can be performed.

---

<div class="post-metadata">

**Author:** ![ddimitrov](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ddimitrov/32/141_2.png) [@ddimitrov](https://discuss.gradle.org/u/ddimitrov)\
**Post date:** [September 19, 2018, 4:42pm UTC](https://discuss.gradle.org/t/support-for-gradle-wrapper-distribution-mirror/26838/8 "2018-09-19T16:42:09Z")

</div>

Ok, it’s here now - a fresh take on the same old chestnut. Allows to override wrapper properties by only specifying environment variables.

> **[ddimtirov/gwo-agent](https://github.com/ddimtirov/gwo-agent)**
>
> Gradle Wrapper Override Agent. Contribute to ddimtirov/gwo-agent development by creating an account on GitHub.

Let me know how it works for you.

I’ve earmarked some improvements as well (search TODO), but they can wait for another day - it is almost 2am and I’m going to bed!
