This message was deleted.
# community-support
s
This message was deleted.
m
Not sure what the question is?
If you want nested blocks that works both from Groovy and Kotlin, use
Action<T>
:
Copy code
abstract class MyExtension {
  fun nested(block: Action<MyNested>) {
    // stuff
  }
}
Gradle generates an overload with closures so that Groovy can use it like Kotlin users:
Copy code
myExtension {
  nested {
    // bla
  }
}
d
Sorry for the delay! The question is more about defining the relationship between one extension and another. In our code, we have the following:
Copy code
abstract class DocumentationPluginExtension : ExtensionAware {
  internal val content = extensions.create<ContentConfiguration>("content")
}

abstract class ContentConfiguration {
  abstract val fontSize: Property<Int>
}
The usage of
create
automatically creates an identical structure as defined above. Alternatively, we could do something like this:
Copy code
abstract class DocumentationPluginExtension : ExtensionAware {
  val content: ContentConfiguration
  fun content(block: ContentConfiguration.() -> Unit) {
    content.block()
  }
}

abstract class ContentConfiguration {
  abstract val fontSize: Property<Int>
}
And it would almost accomplish the same thing- although there are some obv things missing, like the instantiation of
ContentConfiguration
. My question is, what is the intended way to draw relationships between two extensions? In the Gradle ecosystem there are a lot of ways to do the same thing- and a lot of common code smells that folks have adopted over the years. We actively want to avoid those, and make sure in our modernization efforts that we're aligned with Gradle's current/future API design plans.
m
I'd go with 2 above, that sounds more maintainable as you have full control what's happening in content {}
Use
Action
instead of Kotlin functions if you care about Groovy users