-
Notifications
You must be signed in to change notification settings - Fork 434
Provide convenient configuration of nested project extensions and conventions #457
Comments
Here is another example of a plugin using nested extensions: https://github.com/GoogleCloudPlatform/app-gradle-plugin/blob/v1.3.3/src/main/java/com/google/cloud/tools/gradle/appengine/core/AppEngineCorePlugin.java#L67-L76 |
The Junit 5 plugin used to do this too before I opened a PR to fix it. class JUnitPlatformExtension {
void selectors(Action<SelectorsExtension> closure) {
closure.execute(getProperty(JUnitPlatformPlugin.SELECTORS_EXTENSION_NAME) as SelectorsExtension)
}
} And how the extensions are added: |
Is there a workaround for this? Is there ANY way to get the nested extensions? i am trying to use the Jaxb plugin which nests the xjc extensions inside the jaxb extensions (https://github.com/jacobono/gradle-jaxb-plugin). How would I customize the xjc extensions? |
I have managed to figure out the workaround for the Jaxb case but it is a complete hack. If someone has a better workaround let me know. Add this method to the script:
Which will then allow you to customize Jaxb as expected:
|
Hi @NikolayMetchev, A simpler workaround would be to cast the outer extension to import org.gradle.jacobo.plugins.extension.XjcExtension
plugins {
id("com.github.jacobono.jaxb") version "1.3.5"
}
jaxb {
val jaxbExtensions = (this as ExtensionAware).extensions
val xjc: XjcExtension by jaxbExtensions
xjc.apply {
destinationDir = "src/generated/java"
}
xsdDir = projectDir.resolve("src").resolve("xsd").relativeTo(rootDir).toString()
} |
Thanks @bamboo that is a much better workaround. |
I think a first step would be to atleast have an extension function as a simple workaround within kotlin-dsl, maybe something like this:
|
@Xerus2000 Slight improvement upon your code here: inline fun <reified T : Any> Any.extensionAware(action: T.() -> Unit) =
(this as ExtensionAware).extensions.configure(T.java, action) |
Closing as delivered |
Although a relatively uncommon pattern, project extensions can themselves be extended.
The Kotlin DSL should provide accessors for all nested extensions found at project schema computation time.
Related forum post: https://discuss.gradle.org/t/make-a-gradle-plugin-compatible-with-kotlin-dsl/23657/3
The text was updated successfully, but these errors were encountered: