I have project with mixed plugins (regulars and co...
# community-support
k
I have project with mixed plugins (regulars and conventions). I have issue with accessing my extension inside my convention plugin. This works:
Copy code
myExtension.mySubExtentions.variable.set("test")
but this throws errors:
Copy code
myExtension {
  mySubExtension {
    variable.set("test")
  }
}
I use code like this to add my base extension as property:
Copy code
@Suppress("UNCHECKED_CAST")
fun <T : Any> Any.requiredExtension(name: String): T =
    (this as ExtensionAware).extensions.getByName(name) as T

val Project.alpha: AlphaExtension
    get() = this.requiredExtension(ALPHA_EXTENSION_NAME)
And then in another plugin:
Copy code
val AlphaExtension.version: VersionExtension
    get() = this.requiredExtension(ALPHA_VERSION_EXTENSION_NAME)
It seems like it's missing accessor in format:
Copy code
fun myExtension(configure: Action<MyExtension>): Unit {do something...}
because at least first level is accessible when I add:
Copy code
fun Project.alpha(configure: Action<AlphaExtension>) {
    configure.execute(alpha)
}
Is this expected behavior? Am I missing something or did something wrong? It works properly when I import my plugin in external project so it seems that normally Gradle adds those Accessors automatically.
v
Where you write "I use code like this to add my base extension as property", this code is not adding any extension anywhere. It is a Kotlin extension property that just gets the extension by name and type, but that is not the accessor consumers of that plugin get.
If your plugins are written in pure Kotlin, you do not get any accessors generated by Gradle.
If your plugins are precompiled script plugins, you would get accessors as normal for plugins that are applied using the
plugins { ... }
block