Android Studio: "Use default gradle wrapper" vs. "Use customizable gradle wrapper"
Asked Answered
D

1

54

What exactly is the difference between Android Studio's Gradle options:

Android Studio->Preferences->Gradle

Use default gradle wrapper (recommended) and Use customizable gradle wrapper?

Background:

I am working on an Android project in Android Studio and using a Gradle wrapper.

However, when I use the Android Studio settings "Use customizable gradlew wrapper" every time my team members sync the Android Studio project using the gui command:

enter image description here

they find the gradle/wrapper/gradle-wrapper.properties date being updated (and resulting in a extra diffs on the git repo).

Switching to "Use default gradle wrapper" seems to solve this issue.

Doubledealing answered 17/7, 2014 at 19:33 Comment(1)
Switching to "Use default gradle wrapper" seems to solve this issue. This is the right answer!Tamworth
R
49

See the IntelliJ IDEA help here:

  • Using the default gradle wrapper means that Gradle controls the version number
  • Using the customizable gradle wrapper means that IDEA controls the version number of the gradle wrapper.

The version number is stored in gradle/wrapper/gradle-wrapper.properties. So when you choose "using the customizable gradle wrapper" each time you are opening the project with IDEA, it will change the property file to adjust the wrapper version you specified in the IDEA project.

For the sake of repeatable builds (even on your continuous build server which doesn't run IDEA) let Gradle control the version number and use the default gradle wrapper.

You can set the version number which is used by Gradle inside your build.gradle with

// needs at least Gradle V1.7
wrapper {
    gradleVersion = '2.2.1'
}

or

// works with every Gradle version
task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

Remark: don't forget that this configuration is only used for the generation of the wrapper. To activate it, you have to execute the generation with gradlew wrapper. This tasks updates the gradle-wrapper.properties which is used afterwards for all wrapper executions.

Recluse answered 25/11, 2014 at 9:16 Comment(8)
It may be worth clarifying that the build.gradle wrapper configuration example provided is to configure the generation of the gradle wrapper scripts and properties file, and not an alternative method of specifying the gradle version for a project with already generated wrapper filesPhilanthropic
Exactly, the build.gradle wrapper configuration example provided configures the generation of the gradle wrapper (executed with gradlew wrapper :-) ). Once it is generated, it is used - whatever is specified in build.gradle.)Recluse
I understand. But it took me quite some research after reading your answer to figure that tidbit out. I was trying to suggest an edit to your (excellent, thank you!) answer to make that part a tad clearer.Philanthropic
You are right. Thank you for pointing that out, I updated my answer. And thanks for the positive feedback :-)Recluse
Why would you want to set this? It's very unlikely that version X of the gradle wrapper wouldn't be able to download version X of gradle.Paulina
Important is that the IDEA setting is "Use the default gradle wrapper". You can skip the entry in the build.gradle, since it is also available in gradle-wrapper.properties. I prefer to change the version number in the build.gradle but this is just my way to do it. See docs.gradle.org/3.4.1/userguide/…Recluse
Gradle wrapper is one thing, but how to define that Gradle shall decide which version of itself that is suitable for the build process? Building on two different HW environments, we try the following. DOES NOT WORK: if (JavaVersion.current() != JavaVersion.VERSION_1_8) { gradleVersion = '2.2.1' } else { gradleVersion = '3.3' } 14:50 RuntimeException: Could not load wrapper properties from ...\wrapper\gradle-wrapper.properties'. (Because we undefined Graddle version in /Project structure)Irresolvable
When you start gradlew it loads gradle/wrapper/gradle-wrapper.properties and checks if the defined version is locally available. If not it downloads it. Then it executes the gradle jar with the version. On the other hand the code of the wrapper is just used to write the version number into gradle-wrapper.properties. So when you have logic there this logic will be ignored unless you call gradle wrapper prior to execute your build task on the target system.Recluse

© 2022 - 2024 — McMap. All rights reserved.