install gradle wrapper when build failes because of wrong gradle version
Asked Answered
D

2

6

I'm new to Gradle and Java development and I'm having a hard time using a Gradle project which requires an old version of Gradle.

Basically, the problem is that every gradle command I run ends up with the same error:

FAILURE: Build failed with an exception.

* Where:
Build file '/var/code/doron/reverb/libpulse-android/build.gradle' line: 10

* What went wrong:
A problem occurred evaluating project ':libpulse-android'.
> Failed to apply plugin [id 'android-library']
   > Gradle version 1.10 is required. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in /var/code/doron/reverb/gradle/wrapper/gradle-wrapper.properties to gradle-1.10-all.zip

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 0s

From what I understood, the recommended way to work with this kind of project is to install and use the gradle wrapper - Use the ./gradlew command instead of the system's gradle. I have searched the internet and reached this web page: https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper Which basically says I should run:

gradle wrapper --gradle-version 1.10

But that ends in the same errors as above!

When searching for an answer, I have encountered this question: Getting error "Gradle version 1.10 is required. Current version is 1.12." when executing "gradle wrapper"? Which have failed to solve my problem. It seems the answers for that question only try to explain why the problem happens and not how to solve it.

Do you see why the problem is absurdly recursive? I can't install a needed version of Gradle in a wrapper because the build fails and the build fails because I don't use a specific version of gradle and I don't use the wrapper which I can't install.

Destined answered 28/9, 2018 at 11:43 Comment(2)
Why are you using such an old version ?. Try with 4.4 or 4.6.Nook
The "recursiveness" of this problem is truly ridiculous. I encountered it myself today.Harpy
R
9

If you don't yet have the Wrapper in your project: what you can do is to create a new temporary Gradle project, configure the wrapper in this project to match your needed gradle version, and then copy the wrapper related files into your initial project. If you already have a wrapper you can simply configure it by changing distribution url in ./gradle/wrapper/gradle.properties:

In details

1) create new empty project

mkdir  tmp-project
cd tmp-project
gradle init

2) change wrapper version

gradle wrapper --gradle-version 1.10

3) check version (this will download the distribution)

$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-1.10-bin.zip
......................................

------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------

4) copy the wrapper related resources to your project:

  • ./gradle/ directory
  • ./gradlew script
  • ./gradlew.bat script
Regularize answered 28/9, 2018 at 11:46 Comment(1)
Thanks, that worked. I have thought about this workaround but I still can't believe this is the way to solve this. Maybe I'll talk about it with the Gradle community.Destined
C
0

open gradle-wrapper.properties in GradleScripts file change distributionUrl like below

#Thu Apr 12 11:14:54 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

don't forget to clean and rebuild project

Casto answered 28/9, 2018 at 11:51 Comment(1)
I have the exact same gradle-wrapper-properties but my distributionUrl is the same as yours only for 1.10. Why are you pointing me to 4.4? I need 1.10.Destined

© 2022 - 2024 — McMap. All rights reserved.