gradle插件与kotlin - 设置布尔扩展属性

时间:2017-12-06 08:06:46

标签: gradle kotlin gradle-plugin

我正在尝试将一个gradle插件从groovy迁移到kotlin。我有一个布尔Property,我想在我的插件扩展中初始化为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)

中会抛出异常

对此有何想法?

1 个答案:

答案 0 :(得分:1)

Kotlin中的

[]是指原始类型。尝试改为指定对象类型:

Boolean::class.java