我收到以下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>'
这是什么错误信息,我该如何解决?
答案 0 :(得分:1)
将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)
}
}
cleanDerbyDbData
是delegated property,并且对于var
,by
右侧的表达式必须返回一个可变值。 creating()
函数返回的PolymorphicDomainObjectContainerDelegateProvider并未提供任何设置者,这就是您所看到的错误。