Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install gradle wrapper when build failes because of wrong gradle version

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.

like image 692
Doron Behar Avatar asked Sep 28 '18 11:09

Doron Behar


People also ask

How do I change Gradle version in Gradle wrapper properties?

One way to upgrade the Gradle version is manually change the distributionUrl property in the Wrapper's gradle-wrapper. properties file. 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.

How do I reset my Gradle wrapper?

Android studio -> Settings -> build tools -> gradle -> Project-level settings -> select Use default gradle wrapper(recommended). And sync gradle and rebuild your project. It's work for me. I hope its helps you.

Where is Gradle Wrapper version set?

Getting started is easy. First install Gradle on your machine, then open up your project directory via the command line. Run gradle wrapper and you are done! You can add the --gradle-version X.Y argument to specify which version of Gradle to use.


1 Answers

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
like image 162
M.Ricciuti Avatar answered Oct 15 '22 05:10

M.Ricciuti