nebula-plugins / gradle-extra-configurations-plugin

Gradle plugin introducing a provided dependency configuration and marking a dependency as optional.
Apache License 2.0
139 stars 18 forks source link

Use with gradle kotlin DSL #42

Open ctzen opened 5 years ago

ctzen commented 5 years ago

Can optional be used with the gradle kotlin DSL? If yes, please provide an example. Thanks.

tkrullmann commented 5 years ago

I've used the following workaround, it works but it's a bit ugly:

plugins {
    id("nebula.optional-base") version "5.0.0"
}

val optional: Closure<*> by extra

dependencies {
    // use optional.toAction() as the 2nd parameter
    implementation("...", optional.toAction())
}

with toAction defined like this

fun <T : Any> Closure<*>.toAction(): Action<T> =
        ConfigureUtil.configureUsing(this)