Hey all, I'm trying to configure other plugins ins...
# plugin-development
a
Hey all, I'm trying to configure other plugins inside my convention plugin and I'm creating an extension for passing the properties, although I need to use
project.afterEvaluate
to configure the underlying plugins, is that the best approach? Thanks in advance ✌️
v
No,
afterEvaluate
is seldomly a good idea. The main effect it has is adding ordering problems, timing problems, and race conditions.
Optimally, those plugins use lazy properties, then you simply write your extension properties to those properties and there is no reason to use it. If not, you could for example use methods in you extension instead of properties.
a
Ya thats another issue I have how can I set a function on my extension with a receiver?
instead of using props
v
As long as context receivers are not usable, just give the receiver as argument instead, unless I misunderstood
a
I'm doing the following Buildscript:
Copy code
plugins {
    `common-plug`
}

test {
   dependencies {
      implementation...
   }
}
common-plug.gradle.kts
Copy code
interface TestExtension {
    val dependencies: Property<JvmComponentDependencies.() -> Unit>

    fun dependencies(block: JvmComponentDependencies.() -> Unit) {
        dependencies = block
    }
}

val extension = project.extensions.create<TestExtension>("test")

project.afterEvaluate {
    testing {
        suites {
            getByName<JvmTestSuite>("test") {
                //common config...
                dependencies {
                    extension.dependencies.get()()
                }
            }
        }
    }
}
e
do you even need to create your own extension? just exposing
Copy code
project.extensions.add(JvmTestSuite::class, "test", testing.suites.getByName("test"))
would make that DSL available at the top level in buildscripts, if that's what you want a shortcut for
a
I think I can't do that the next parameter after the name is a vararg for constructing a JvmTestSuite right?
e
extensions.add
is not the same as
extensions.create
🙌 1
👀 1