Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly write a gradle-wrapper.properties file?

Tags:

gradle

gradlew

Can anyone please tell me if there is any advantage of gradlew over gradle?

Also I have some doubts on the gradle-wrapper.properties file.

Initially when I ran

C:\project_basedir>gradle wrapper

I found the following content in gradle-wrapper.properties file.

#Thu Jun 12 17:06:10 IST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip

To stop downloading the zip file I have followed the steps as suggested in chapter 61.1. Configuration of gradle documentation and added the gradle-1.12-bin.zip file from my local gradle installation to <Project_Base>\gradle\wrapper directory. and modified the properties files as follows:

#Thu Jun 12 17:06:10 IST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-1.12.zip

It saved the downloading time.

My Gradle installtion structure is as below:

C:\Users\sanjeev\Softwares\Gradle\gradle-1.12\bin

I have set system property GRADLE_USER_HOME to my local installtion dir i.e. C:\Users\sanjeev\Softwares\Gradle\gradle-1.12. But the distributionBase & distributionPath options are not picking the value.

I even tried to modify the values as:

distributionBase=file\:///c:/Users\sanjeev\Softwares\Gradle\gradle-1.12.zip

It did not work.

Exception in thread "main" java.lang.RuntimeException: Base: file:/C:/Users/sanjeev/Softwares/Gradle/gradle-1.12 is unknown

Can someone please suggest what am I missing here?

Or in a nutshell how to define distributionBase,distributionPath,zipStoreBase and zipStorePath properly?

like image 766
sanjeev Avatar asked Jun 12 '14 12:06

sanjeev


People also ask

What is Gradle wrapper properties file?

The Gradle wrapper is a script you add to your Gradle project and use to execute your build. The advantages are: you don't need to have Gradle installed on your machine to build the project. the wrapper guarantees you'll be using the version of Gradle required by the project.

How do I edit Gradle wrapper properties?

Open gradle-wrapper. properties(go to Gradle > wrapper > gradle-wrapper. properties and manually change the distributionUrl property in the file.

Where do Gradle wrapper properties go?

The content of gradle-wrapper properties file is as follows: distributionBase=GRADLE_USER_HOME. distributionPath=wrapper/dists. distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip.

Should Gradle wrapper properties be committed?

Using the wrapper task ensures that any optimizations made to the Wrapper shell script or batch file with that specific Gradle version are applied to the project. As usual, you should commit the changes to the Wrapper files to version control.


2 Answers

The advantage of gradlew over gradle is that:

  1. You don't have to have gradle installed on your machine in order to build your project.
  2. You can control which version of gradle is needed to build your project.

I'm not sure of the point of changing the distribution url in the properties file. The whole point of the wrapper is that it downloads gradle. If you get it locally you might as well install and use gradle instead. The wrapper will only download the distribution once anyway and store it for each user (hence the use of GRADLE_USER_HOME).

GRADLE_USER_HOME is an environment property, not a system property. If you want to change the gradle user home using system properties you need to set 'gradle.user.home'.

like image 91
mikea Avatar answered Nov 04 '22 14:11

mikea


The best way to get a proper gradle-wrapper.properties is to run the wrapper task using gradle wrapper. But that needs a local gradle installation. When editing the content of that file manually you need to be careful with escaping. Try this distributionUrl:

distributionUrl=file\://gradle/wrapper/gradle-1.12-bin.zip

One more comment: It might be easier to maintain if you put your gradle installation in a local bin repository (e.g in your nexus or artifactory repository) and let gradlew download the referenced gradle bin from there. The benefit is, that you just need to update the distributionURL.

like image 4
Rene Groeschke Avatar answered Nov 04 '22 15:11

Rene Groeschke