All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unbrokendome.gradle.pluginutils.test.spek.MemoizedGradleTask.kt Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package org.unbrokendome.gradle.pluginutils.test.spek

import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.spekframework.spek2.dsl.LifecycleAware
import org.spekframework.spek2.lifecycle.MemoizedValue
import kotlin.reflect.KClass


/**
 * Creates a memoized Gradle task.
 *
 * @param taskType the type of task to create
 * @param name the task name
 * @param config an optional block for configuring the task
 */
fun  LifecycleAware.gradleTask(
    taskType: KClass,
    name: String? = null,
    config: T.() -> Unit = {}
): MemoizedValue {
    val project: Project by memoized()
    val actualName = name ?: taskType.simpleName?.decapitalize() ?: "task"
    return memoized {
        project.tasks.create(actualName, taskType.java, Action(config))
    }
}


/**
 * Creates a memoized Gradle task.
 *
 * @param T the type of task to create
 * @param name the task name
 * @param config an optional block for configuring the task
 */
inline fun  LifecycleAware.gradleTask(
    name: String? = null, noinline config: T.() -> Unit = {}
) =
    gradleTask(T::class, name, config)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy