Maanrifa Bacar Ali
10/07/2025, 3:31 PMbuild.gradle.kts — like how kotlin-dsl generates accessors for extensions?Vampire
10/07/2025, 3:45 PMVampire
10/07/2025, 3:49 PMMaanrifa Bacar Ali
10/07/2025, 6:51 PMkotlin
import komogen.gradle.plugin.flagset.FlagSet
import komogen.gradle.plugin.generics.Generics
import komogen.gradle.plugin.ionum.IonspinBignum
import komogen.gradle.plugin.kodate.KotlinxDateTime
import komogen.gradle.plugin.koser.KotlinxSerialization
import komogen.gradle.plugin.patternizer.Patternizer
import komogen.gradle.plugin.sqlite.SqliteLocal
import komogen.gradle.plugin.supabase.Supabase
import komogen.gradle.plugin.supabase.SupabaseClient
import komogen.gradle.schematizer.postgres.PostgresSchematizer
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.komogen)
alias(libs.plugins.komogen.plugin.flagset)
alias(libs.plugins.komogen.plugin.generics)
alias(libs.plugins.komogen.plugin.ionspin.bignum)
alias(libs.plugins.komogen.plugin.kotlinx.datetime)
alias(libs.plugins.komogen.plugin.kotlinx.serialization)
alias(libs.plugins.komogen.plugin.patternizer)
alias(libs.plugins.komogen.plugin.sqlite)
alias(libs.plugins.komogen.plugin.supabase)
alias(libs.plugins.komogen.schematizer.postgres)
}
komogen {
basePackageName = "com.example"
sensitiveConfigDirectory = gradle.gradleUserHomeDir.resolve("komogen")
repositoryManager {
name = "ExampleRepositoryManager"
environment = Client
dataSource = local<SqliteLocal>() hybridWith cloud<SupabaseClient>()
}
schematizers {
register<PostgresSchematizer>()
}
generatorPlugins {
register<FlagSet>()
register<Generics>()
register<IonspinBignum>()
register<KotlinxDateTime>()
register<KotlinxSerialization>()
register<Patternizer>()
register<Supabase>()
}
ionspinBignum {
serializationKotlinx = true
}
kotlinxSerialization {
serializationFormat = Json
}
supabase {
runtime = true
clientFactoryFunction.enabled = true
}
}
Now, to explain a bit more — I’m currently developing the Komogen plugin, which provides the main komogen {} DSL.
Child plugins can self-register when the main Komogen plugin is applied, extending the main DSL with their own sub-DSLs. This all works nicely thanks to kotlin-dsl and Gradle’s extension mechanism.
But I want to go a step further.
As you can see, there’s a generatorPlugins {} block that uses a custom ExtensiblePolymorphicDomainObjectContainer to handle plugins dynamically (since the main plugin doesn’t know about child plugins).
The problem?
Users still have to manually import classes from the child plugin sources, which I’d really like to avoid.
So my goal is to generate type-safe extensions for each applied child plugin — functions that would be available only inside the generatorPlugins {} block, without requiring any imports from the user’s build script.
That’s where I’ve hit some limitations with ExtensionContainer and kotlin-dsl.
I don’t see why only kotlin-dsl should be able to do that kind of magic. 😄
I also want to improve the repositoryManager {} block in a similar way — removing the need for imports and ideally getting rid of the local<T>() and cloud<T>() API in favor of something cleaner.
All of this would be possible if I can figure out a way to inject generated code directly into the build script classpath.Vampire
10/07/2025, 7:12 PMVampire
10/07/2025, 7:13 PMorg.gradle.kotlin.dsl.
But that would mean you have classes in that package in your plugin and I personally majorly dislike that as it is not Gradle code.Vampire
10/07/2025, 7:14 PMVampire
10/07/2025, 7:15 PMVampire
10/07/2025, 7:17 PMMaanrifa Bacar Ali
10/07/2025, 10:54 PMVampire
10/07/2025, 11:58 PMis there a detailed and official page or article about them?I don't think so