定义删除任务时出错

时间:2018-05-29 22:15:04

标签: gradle-kotlin-dsl

我收到以下DSL脚本块的错误。

val DerbyDbDataFolder: File = file("DerbyDbData")
val DerbyLog: File = file("derby.log")

tasks {
    var cleanDerbyDbData by creating (Delete::class) {
        delete(DerbyDbDataFolder)
        delete(DerbyLog)
    }

    "clean" {
        dependsOn(cleanDerbyDbData)
    }
}

但是我收到以下错误消息。

       var cleanDerbyDbData by creating (Delete::class) {
                               ^ Missing 'setValue(Nothing?, KProperty<*>, Delete)' method on delegate of type 'PolymorphicDomainObjectContainer<Delete>'

这是什么错误信息,我该如何解决?

1 个答案:

答案 0 :(得分:1)

TLDR

cleanDerbyDbData定义为val而不是var

val DerbyDbDataFolder: File = file("DerbyDbData")
val DerbyLog: File = file("derby.log")

tasks {
    val cleanDerbyDbData by creating (Delete::class) {
        delete(DerbyDbDataFolder)
        delete(DerbyLog)
    }

    "clean" {
        dependsOn(cleanDerbyDbData)
    }
}

详细

cleanDerbyDbDatadelegated property,并且对于varby右侧的表达式必须返回一个可变值。 creating()函数返回的PolymorphicDomainObjectContainerDelegateProvider并未提供任何设置者,这就是您所看到的错误。