Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare gradle version 5.0 in build.gradle?

I used task wrapper when Gradle was 4.x but when I change gradleVersion to 5.0 , gradle wrapper states that it can't add a task with the same name. This didn't happen when it was 4.x when I could just change from 4.8 to 4.9 without issues. Does Gradle changed how task wrapper works?

like image 796
Arkyo Avatar asked Nov 28 '18 14:11

Arkyo


People also ask

How do I mention Gradle version in build Gradle?

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

Defining a custom wrapper task in your build script has been deprecated since Gradle 4.8 version, see Gradle 4.8 depreciations (section Overwriting Gradle's built-in tasks" section)

Since version 4.8 (and before 5.0) you should have a warning message as below if you still define a custom wrapper task:

$ ./gradlew clean --warning-mode all

> Configure project :

Creating a custom task named 'wrapper' has been deprecated and is scheduled to be removed in Gradle 5.0.

You can configure the existing task using the 'wrapper { }' syntax or create your custom task under a different name.'.

As announced, the support for custom wrapper task has been removed in Gradle 5.0, so you need to use the new way for configuring the Wrapper:

// Configuring the wrapper, the old way (gradle < 4.8 )
// see https://docs.gradle.org/4.4/userguide/gradle_wrapper.html#sec:wrapper_generation
task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionType = Wrapper.DistributionType.BIN
}

// Configuring the wrapper, the new way (since Gradle 4.8) 
// see https://docs.gradle.org/current/userguide/gradle_wrapper.html#customizing_wrapper
wrapper{
    gradleVersion = '5.1'
    distributionType = Wrapper.DistributionType.BIN
}
like image 108
M.Ricciuti Avatar answered Nov 08 '22 20:11

M.Ricciuti