Gradle Custom Plugin:不推荐使用Task.leftShift(Closure)方法,并计划在Gradle 5.0中删除它

时间:2017-09-23 13:30:03

标签: android gradle groovy

我的自定义gradle插件如下

package my.own.gradle

import org.gradle.api.*

class GroovinPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.extensions.create("groovin", GroovinPluginExtension)
        project.task('groove') << {
            println project.groovin.message
        }
    }
}

class GroovinPluginExtension {
    def String message = 'We be groovin\''
}

根据example。我收到了警告:

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

我该怎么办?

1 个答案:

答案 0 :(得分:1)

需要将<<更改为doLast,如下所示

package my.own.gradle

import org.gradle.api.*

class GroovinPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.extensions.create("groovin", GroovinPluginExtension)
        project.task('groove') {
            doLast {
                println project.groovin.message
            }
        }
    }
}

class GroovinPluginExtension {
    def String message = 'We be groovin\''
}