How do I overwrite a task in gradle kotlin-dsl

2019-05-16 21:47发布

问题:

In Groovy, I overwrite a task like this:

task jar(overwrite: true) {
    ...
}

How do I do that with Kotlin-dsl? I know that I can create a task like this:

tasks {
     val jar by creating {
          ...
     }
}

but I can't find the equivalent way to declare it as overwrite, this leads to an error

回答1:

By opening an issue on the kotlin-dsl github I found the correct syntax:

tasks.replace("jar") {
    ...
}

However, this is the old way and does not work within a tasks { } block, so this issue will be further tracked here