Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I overwrite a task in gradle kotlin-dsl

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

like image 896
xeruf Avatar asked Jan 31 '18 23:01

xeruf


People also ask

How do I edit a task in Gradle?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. icon. In the list that opens, select Run Gradle task. In the Select Gradle Task dialog, specify the project and the task that you want to execute before launching the project.

How do I skip a task in Gradle?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.

How do I define a task in Gradle?

Each project is made up of different tasks and a task is a piece of work which a build performs. The task might be compiling some classes, storing class files into separate target folder, creating JAR, generating Javadoc, or publishing some achieves to the repositories.

What is the Kotlin Gradle DSL?

Gradle's Kotlin DSL provides an alternative syntax to the traditional Groovy DSL with an enhanced editing experience in supported IDEs, with superior content assist, refactoring, documentation, and more.


1 Answers

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

like image 60
xeruf Avatar answered Oct 04 '22 04:10

xeruf