123

I want to use Gradle 1.10 instead of 1.9. I cannot seem to find where to change this.

If I put this:

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}

in my build.gradle and rebuild, it is built with Gradle 1.9 again (so nothing actually happens).

These seem to be all the settings: (and IntelliJ's help section about Gradle doesn't help at all :( ) What does "not configured for the current" project mean?

Mahozad
  • 18,032
  • 13
  • 118
  • 133
Bloke
  • 2,229
  • 3
  • 22
  • 27
  • 1
    Did you regenerate the wrapper with `gradle(w) wrapper` after changing `gradleVersion`? – Peter Niederwieser Aug 08 '14 at 13:54
  • 2
    have tried this: http://stackoverflow.com/questions/24460299/android-studio-says-to-use-gradle-1-10-but-new-version-is-1-12/24628527#24628527 just delete the wrapper files and then execute the `wrapper` task again – The End Aug 08 '14 at 13:57
  • No need to delete any files. – Peter Niederwieser Aug 08 '14 at 13:58
  • Oh, that should be it. Can I do this in IntelliJ somehow or do I have to use the cmd? – Bloke Aug 08 '14 at 14:13
  • 1
    Gradle tasks can be run from IntelliJ, so you should be able to run the wrapper task as well. Also, maybe this is what "use customizable gradle wrapper" is about (but I'm not sure). – Peter Niederwieser Aug 08 '14 at 14:54
  • 1
    Thanks guys for your help, I managed to make it work by changing to *customizable gradle wrapper* and regenerating the wrapper by executing the `wrapper` task. I am still confused what *default gradle wrapper* actually is, though. – Bloke Aug 14 '14 at 14:44
  • @Bloke http://stackoverflow.com/a/27122704/553941 explains quite well. – Pijusn Apr 09 '15 at 07:42
  • Possible duplicate of [Android Studio: "Use default gradle wrapper" vs. "Use customizable gradle wrapper"](http://stackoverflow.com/questions/24811997/android-studio-use-default-gradle-wrapper-vs-use-customizable-gradle-wrappe) – Louis CAD Aug 20 '16 at 15:41

11 Answers11

162

The easiest way is to execute the following command from the command line (see Upgrading the Gradle Wrapper in documentation):

./gradlew wrapper --gradle-version 5.5

Moreover, you can use --distribution-type parameter with either bin or all value to choose a distribution type. Use all distribution type to avoid a hint from IntelliJ IDEA or Android Studio that will offer you to download Gradle with sources:

./gradlew wrapper --gradle-version 5.5 --distribution-type all

Or you can create a custom wrapper task

task wrapper(type: Wrapper) {
    gradleVersion = '5.5'
}

and run ./gradlew wrapper.

Michael
  • 53,859
  • 22
  • 133
  • 139
52

Open the file gradle/wrapper/gradle-wrapper.properties in your project. Change the version in the distributionUrl to use the version you want to use, e.g.,

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Aperifons
  • 537
  • 4
  • 2
  • 6
    better to use the gradle task they created for this purpose so the scripts update properly, etc. – dabluck Jan 11 '17 at 15:42
  • they also update their binary files and scripts, which you do not get unless you run the update task. this could potentially create incompatibilties – dabluck Sep 12 '17 at 20:18
  • 1
    Yep. See [Upgrading the Gradle Wrapper](https://docs.gradle.org/4.5.1/userguide/gradle_wrapper.html#sec:upgrading_wrapper) in Gradle documentation. – Ilya Serbis Feb 20 '18 at 18:20
6

You can set the version of Gradle generated by the wrapper task.
Note that this solution is in Kotlin DSL (build.gradle.kts).

Put this code in your top-level build.gradle.kts file:

tasks.wrapper {
    gradleVersion = "7.4"
    // You can either download the binary-only version of Gradle (BIN) or
    // the full version (with sources and documentation) of Gradle (ALL)
    distributionType = Wrapper.DistributionType.ALL
}

Whenever you want to change Gradle version:

  1. Update the version above to your desired version
  2. Execute Gradle wrapper task: ./gradlew wrapper
  3. Sync the IDE (from Gradle sidebar -> reload icon)
Mahozad
  • 18,032
  • 13
  • 118
  • 133
5

./gradlew wrapper --gradle-version=5.4.1 --distribution-type=bin

https://gradle.org/install/#manually

To check:

 ./gradlew tasks

To input it without command:

go to-> gradle/wrapper/gradle-wrapper.properties distribution url and change it to the updated zip version

output:

 ./gradlew tasks
Downloading https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
...................................................................................

Welcome to Gradle 5.4.1!

Here are the highlights of this release:
 - Run builds with JDK12
 - New API for Incremental Tasks
 - Updates to native projects, including Swift 5 support

For more details see https://docs.gradle.org/5.4.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Starting Daemon 
4

I just wanted to chime in that I hit this after updating Android Studio components.

What worked for me was to open gradle-wrapper.properties and update the gradle version used. As of now for my projects the line reads:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
MacD
  • 783
  • 7
  • 23
4

I was facing same issue for changing default gradle version from 5.0 to 4.7, Below are the steps to change default gradle version in intellij enter image description here
1) Change gradle version in gradle/wrapper/gradle-wrapper.properties in this property distributionUrl

2) Hit refresh button in gradle projects menu so that it will start downloading new gradle zip version

Saurabh
  • 7,525
  • 4
  • 45
  • 46
3

In build.gradle add wrapper { gradleVersion = '6.0' }

k4dima
  • 6,070
  • 5
  • 41
  • 39
2

The 'wrapper' task in gradle is called if gradlew command is used, if you use gradle command to build the wrapper task is not called. So, there are two ways you can change your gradle version.

  1. Use 'gradlew build' command, this command will call the wrapper task that you mentioned. That task will change the 'distributionUrl' parameter in gradle-wrapper.properties file and it will automatically download the gradle version you want. Example distributionUrl in the file for version 4.2. distributionUrl=https://services.gradle.org/distributions/gradle-4.2-bin.zip

  2. If you are not using gradle wrapper simply download the version of the gradle you want and set environment variable path and also show it to IDEA.

P.S. for more information about gradle wrapper I suggest you to read: https://docs.gradle.org/current/userguide/gradle_wrapper.html

Oguz Ozcan
  • 1,497
  • 13
  • 21
2

This question is really old, but current Intellij IDEA (Android Studio) have this in a dialog under: Project Structure > Project > Gradle Version

enter image description here

gcb
  • 13,901
  • 7
  • 67
  • 92
1

First, let gradle set the correct distribution Url

cd projectDirectory
./gradlew wrapper --gradle-version 2.3.0

Then - might not be needed but that's what I did - edit the project's build.gradle to match the version

    dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

Finally, delete the folders .gradle and gradle and the files gradlew and gradlew.bat. (Original Answer)

Now, rebuild the project.

As the other answers did not suffice for me and the comment pointing out these additional steps is easy to overlook, here as a separate answer

lucidbrot
  • 5,378
  • 3
  • 39
  • 68
1

The easiest way to update the gradle in the intellij is, to remove the existing gradle folder in the project and automatically intellij will download the latest. For instance I had 6.41 as the downloaded version. I just removed this gradle folder and it automatically downloaded to 7.1. It might be helpful for someone..

Mohan
  • 457
  • 6
  • 15