https://kotlinlang.org logo
Title
m

Matt Nelson

02/09/2023, 3:59 PM
Anyone familiar with creating `Gradle Plugin`s? I'm trying to do something on closure.
plugins {
    id("my-plugin")
}

myPluginExtension {
    // Configure it
}

// I'm trying to ensure that at this line here in the build.gradle(kts) file (after closure), everything gets configured
open class MyPlugin: Plugin<Project> {
    override fun apply(target: Project) {
        val extension = target.extensions.create(
            "myPluginExtension",
            MyPluginExtension::class.java,
            target,
        )
        
        // What I'm trying to do, much like an action
        // that gets lazily invoked.
        extension.afterClosure { it ->
             it.configure()
        }
    }

    private val MyPluginExtension.configure() {
        // setup
    }
}
e

eygraber

02/09/2023, 4:55 PM
Probably better off asking in the #gradle channel, but that's only meant for Kotlin + Gradle discussions. Gradle has their own Slack https://gradle-community.slack.com/signup#/domain-signup
b

Big Chungus

02/09/2023, 7:13 PM
What you need is gradle's lazy Property and Provider to store data
m

Matt Nelson

02/09/2023, 7:40 PM