varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.51k stars 66 forks source link

Use Gradle @Nested annotation? #131

Closed bitspittle closed 11 months ago

bitspittle commented 2 years ago

Kobweb's Gradle blocks are nested, e.g.

kobweb {
   index { ... }
}

kobwebx {
   markdown { ... }
}

We're doing this manually right now using nested ExtensionAware.create calls but I just learned about the @Nested annotation. Maybe that can clean up the code a bit?

bitspittle commented 11 months ago

According to ChatGPT4, the way we're writing block logic in Kobewb (via ExtensionAware) is actually the preferred approach:


Using the ExtensionAware and extensions API is a more modern approach to defining extensions and nested configurations in Gradle, especially when using the Kotlin DSL. This is often preferred for several reasons:

  1. Immutability & Laziness: By using properties (like Property<String>) from Gradle's API, you can make your extensions and tasks lazy-configured. This means configuration won't be evaluated until it's necessary, leading to faster configuration times.

  2. Default Values & Convention: With properties, you can easily provide default values or conventions, making it easier for users of your plugin.

  3. Better Kotlin DSL Interoperability: Your approach is more idiomatic for the Kotlin DSL. It makes using the plugin more natural for projects written in the Kotlin DSL.

  4. Flexibility: By using the extensions API, you can dynamically add or modify nested blocks, giving more flexibility in structuring your plugin's configuration DSL.

Now, should you prefer this over @Nested? Here are some thoughts:

In summary:

That said, always consider the needs of your users and the context in which your plugin will be used. Depending on the user base and their preferences, one approach might be more advantageous than the other.