I need to convert a gradle build script, which is written in Groovy, into Kotlin. The problem is, that in the Groovy build file in one task another task, which was defined before, is executed. However, it appears that in Kotlin there is no support for that, at least I could not find any in the API.
I have studied the API and searched for similar problems, but I could not find anything useful.
The Groovy code looks like this:
task doSomething () {
...
}
task anotherTask () {
...
doSomething.execute()
...
}
How would this call be translated into Kotlin?
doSomething.execute()
You should never call execute() on a task. Instead set the inputs, outputs and dependencies correctly, and Gradle will call the task for you if it needs to.
something like:
tasks {
val doSomething by registering {
doLast {
println("running doSomething")
}
}
val anotherTask by registering {
dependsOn(doSomething)
doLast {
println("Running anotherTask")
}
}
}
Then:
$ gradle anotherTask
> Task :doSomething
running doSomething
> Task :anotherTask
Running anotherTask
BUILD SUCCESSFUL in 746ms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With