我正在尝试将一个gradle插件从groovy迁移到kotlin.我有一个布尔属性,我想在我的插件扩展中初始化为false:
open class MyPluginExtension(project: Project) {
val myBooleanProperty: Property<Boolean> = project.objects.property(Boolean::class.java)
init {
myBooleanProperty.set(false)
}
}
这失败了
java.lang.IllegalArgumentException: Cannot set the value of a property of type boolean using an instance of type java.lang.Boolean.
org.gradle.api.internal.provider.DefaultPropertyState #set(T)中抛出异常
有什么想法吗?
最佳答案 Kotlin中的Boolean :: class.java指的是原始类型.请尝试指定Object类型:
val myBooleanProperty: Property<Boolean> = project.objects.property(Boolean::class.javaObjectType)