Custom task registration

Hello,

I have tasks like this

val downloadFigletFonts by registering(de.undercouch.gradle.tasks.download.Download::class) {
    src("....")
    dest("$buildDir/assets/...")
    onlyIfModified(true)
    useETag("all") // Use the ETag on GH
}

I rewritten those as custom task so now I can use

val download1 by registering(MyDownload::class) {
    sourceUrl.set("...")
}

However I experimented with a custom registering extension method, the original code is

fun <T : Any, C : PolymorphicDomainObjectContainer<T>, U : T> C.registering(
    type: KClass<U>,
    action: U.() -> Unit
): RegisteringDomainObjectDelegateProviderWithTypeAndAction<out C, U> =
    RegisteringDomainObjectDelegateProviderWithTypeAndAction.of(this, type, action)

So I tried to write

fun <C : PolymorphicDomainObjectContainer<Task>> C.registeringDownload(
    src: String,
): RegisteringDomainObjectDelegateProviderWithTypeAndAction<out C, Download> =
    RegisteringDomainObjectDelegateProviderWithTypeAndAction.of(this, Download::class) {
        src(src)
        dest("${buildDir}/gangshit-figlet-fonts-master.zip")
        onlyIfModified(true)
        useETag("all") // Use the ETag on GH
    }

And declared this way

val download1 by registeringDownload("...")

My question is do you think it’s a good approach?

How about

fun TaskContainer.registeringDownload(src: String) = registering(Download::class) {
    src(src)
    dest(layout.buildDirectory.file("gangshit-figlet-fonts-master.zip"))
    onlyIfModified(true)
    useETag("all") // Use the ETag on GH
}

?

Haha how come I didn’t even think about that ?

Regardless, is it conceptually an OK idea, compared to other approaches like custom task.

If you only need to support Kotlin DSL, why not.
I’d even say it is preferable.
You do not add behavior, you do not add new inputs or outputs, …
You just want to DRY with the configuration of the task, so to me the approach looks perfectly fine.