How to declare gradle version 5.0 in build.gradle?

心不动则不痛 提交于 2019-11-28 04:47:53

问题


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?


回答1:


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
}


来源:https://stackoverflow.com/questions/53521437/how-to-declare-gradle-version-5-0-in-build-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!