commonMain.co.touchlab.skie.plugin.util.TaskDoOptimized.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin-impl-jvm Show documentation
Show all versions of gradle-plugin-impl-jvm Show documentation
Internal implementation for SKIE Gradle plugin.
@file:Suppress("ObjectLiteralToLambda")
package co.touchlab.skie.plugin.util
import org.gradle.api.Action
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider
// We need to use an anonymous class instead of lambda to keep execution optimizations.
// https://docs.gradle.org/7.4.2/userguide/validation_problems.html#implementation_unknown
inline fun Task.doFirstOptimized(crossinline action: () -> Unit): Task =
doFirst(
object : Action {
override fun execute(task: Task) {
action()
}
},
)
inline fun TaskProvider.configureDoFirstOptimized(crossinline action: () -> Unit) =
configure {
doFirstOptimized(action)
}
inline fun Task.doLastOptimized(crossinline action: () -> Unit): Task =
doLast(
object : Action {
override fun execute(task: Task) {
action()
}
},
)
inline fun TaskProvider.configureDoLastOptimized(crossinline action: () -> Unit) =
configure {
doLastOptimized(action)
}