gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

TaskContainer.replace(String, Class<T>) not found #1349

Closed fonix232 closed 5 years ago

fonix232 commented 5 years ago

While trying to use TaskContainer.replace, the typed variant is not found.

Expected Behavior

Calling tasks.replace("taskName", MyOwnTask::class) { /* commands */ } should compile.

Current Behavior

Calling tasks.replace("taskName", MyOwnTask::class) { /* commands */ } results in the following error message:

Too many arguments for public abstract fun replace(name: String): Task defined in org.gradle.api.tasks.TaskContainer

Context

I'm trying to override default tasks provided by certain plugins. Some of these tasks have type-specific properties that would need to be overwritten, but the typed version of the replace command is not found.

Steps to Reproduce (for bugs)

  1. Create new Android project
  2. In the project build.gradle.kts, add Dokka (used as an example)
  3. In the allprojects

Your Environment

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_202 (Oracle Corporation 25.202-b08)
OS:           Mac OS X 10.14.3 x86_64

AS 3.4 Beta 4 Kotlin 1.3.21

StefMa commented 5 years ago

In generell I agree with you that this should be added. But in the other hand - why do you want to replace the task instead of seting it up?

On Sun, Feb 17, 2019, 10:32 PM Jozsef Kiraly notifications@github.com wrote:

While trying to use TaskContainer.replace, the typed variant is not found. Expected Behavior

Calling tasks.replace("taskName", MyOwnTask::class) { / commands / } should compile. Current Behavior

Calling tasks.replace("taskName", MyOwnTask::class) { / commands / } results in the following error message:

Too many arguments for public abstract fun replace(name: String): Task defined in org.gradle.api.tasks.TaskContainer

Context

I'm trying to override default tasks provided by certain plugins. Some of these tasks have type-specific properties that would need to be overwritten, but the typed version of the replace command is not found. Steps to Reproduce (for bugs)

  1. Create new Android project
  2. In the project build.gradle.kts, add Dokka (used as an example)
  3. In the allprojects

Your Environment


Gradle 5.2.1

Build time: 2019-02-08 19:00:10 UTC Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL: 1.1.3 Kotlin: 1.3.20 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_202 (Oracle Corporation 25.202-b08) OS: Mac OS X 10.14.3 x86_64

AS 3.4 Beta 4 Kotlin 1.3.21

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gradle/kotlin-dsl/issues/1349, or mute the thread https://github.com/notifications/unsubscribe-auth/AJwYe9nF8Zhks_kQ8VlxIGWJ2076yEFQks5vOcp8gaJpZM4a_zha .

fonix232 commented 5 years ago

In some cases (looking at Dokka right now) it's not possible to use a certain plugin's own configuration block, as the compiler freaks out for some reason. In this case, I was trying to apply a generic Dokka generation to all projects using the subproject { } block in the main build.gradle - however I could not make use of the dokka block even though the plugin was imported and applied (same thing works just fine with Detekt, for example). But overriding the main Dokka call, and supplying the configuration there worked fine.

eskatos commented 5 years ago

There's no such API so the failure is expected.

Here's how you could use the existing API replace(name, type) and a subsequent call to named<Type>(name, action) to configure the replaced task.

tasks {
    replace("taskName", MyOwnTask::class)
    named<Copy>("taskName") { /* commands */ }
}

If you want a new API added to do that in a single statement, please open an issue on the gradle/gradle repository.