如何在build.gradle中声明gradle版本5.0? [英] How to declare gradle version 5.0 in build.gradle?
问题描述
当Gradle为4.x时,我使用了任务包装器
,但是当我将 gradleVersion
更改为5.0时,gradle包装器状态无法添加相同名称的任务。当我将其从4.8更改为4.9时,即使是4.x,也没有发生这种情况。 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?
推荐答案
定义自定义<自Gradle 4.8版本起,构建脚本中的code> wrapper 任务已被弃用,请参见第4.8级折旧(覆盖Gradle的内置任务部分)
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)
在4.8(及5.0之前)中,如果仍然定义自定义包装器
任务,则应该显示以下警告消息:
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
$ ./gradlew clean --warning-mode all
>配置项目:
创建名为包装器的自定义任务已被弃用,并计划在Gradle 5.0中删除。
Creating a custom task named 'wrapper' has been deprecated and is scheduled to be removed in Gradle 5.0.
您可以使用$ b $配置现有任务。 b'wrapper {}'语法或使用其他
名称创建您的自定义任务。'。
You can configure the existing task using the 'wrapper { }' syntax or create your custom task under a different name.'.
ce,自定义 wrapper
任务的支持已在Gradle 5.0中删除,因此您需要使用新的方式来配置包装器:
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
}
这篇关于如何在build.gradle中声明gradle版本5.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!