Gradle: [Kotlin DSL] Task type-safe accessor generated with type Any if task type is internal

Created on 16 May 2019  路  1Comment  路  Source: gradle/gradle

Now Kotlin DSL generate type-safe accessors for tasks and task type is used in the configuration lambda.
But if task type is internal, will be generated accessor with type Task instead of the public parent type

Expected Behavior

Accessor should be generated with a closest parent public type.
Imagine this hierarchy:

abstract class MyCustomTask : DefaultTask()

internal class MyCustomTaskImpl : MyCustomTask()

Should be generated this accessor:

val TaskContainer.`myCustomTask`: TaskProvider<MyCustomTask>
    get() = named<MyCustomTask>("myCustomTask")

Current Behavior

Will be generated this accessor

val TaskContainer.`myCustomTask`: TaskProvider<Task>
    get() = named("myCustomTask")

Also, configuration lambda type will be Any instead of Task:

tasks.myCustomTask {
   // this receiver has type Any, not Task, but it's probably some invoke function resolution problem
}

Currently, Kotlin Gradle plugin itself has this problem because provides new Worker-based tasks implementation which is internal, so this broke type-safe accessors.
See https://youtrack.jetbrains.com/issue/KT-31435

bug contributor kotlin-dsl

Most helpful comment

Fixed in https://github.com/gradle/gradle/pull/9981, will be in Gradle 5.6

>All comments

Fixed in https://github.com/gradle/gradle/pull/9981, will be in Gradle 5.6

Was this page helpful?
0 / 5 - 0 ratings