Java.lang.VerifyError creates a gradle task with kotlin

I am trying to write a gradle task with kotlin, this is my code .:

GreetingTask.kt

class GreetingTask : DefaultTask() {
    @TaskAction
    fun greet() {
        println("greet!")
    }
}

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.613"
    }
}

apply plugin: "kotlin"

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:0.12.613"
    compile gradleApi()
}

GreetingTaskTest

class GreetingTaskTest {

    @Test
    public fun canAddTaskToProject() {
        val project = ProjectBuilder.builder().build()
        val task = project.task(hashMapOf("type" to javaClass<GreetingTask>()), "greeting")
        assertTrue(task is GreetingTask)
    }
}

When starting the test, this now results in:

java.lang.VerifyError at GreetingTaskTest.kt:20
// reason -> Cannot inherit from final class

What is this line:

val task = project.task(hashMapOf("type" to javaClass<GreetingTask>()), "greeting")

What I would like to know:

Where does this problem come from and how to fix it?

+4
source share
1 answer

Classes in Kotlin are final by default, compared to open in java.

Declare the class GreetingTaskas "open" and this error message has disappeared.

open class GreetingTask : DefaultTask() { 
    ...
}
+6
source

Source: https://habr.com/ru/post/1598343/


All Articles