https://kotlinlang.org logo
#ksp
Title
# ksp
m

Mohammed Toufeeq Ahamed

09/20/2023, 9:46 AM
Hi, I was setting up a project with Gradle Convention Plugins, where in I need to setup ksp plugin for komapper. Komapper can be configured by specifying options in gradle script, I'm stuck here on how to set this up in Convention Plugins.
Copy code
ksp {
  arg("komapper.enumStrategy", "ordinal")
  arg("komapper.namingStrategy", "UPPER_SNAKE_CASE")
}
Any help would be really helpful. Thanks!
g

glureau

09/20/2023, 9:51 AM
Copy code
class MyPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        target.apply(plugin = "com.google.devtools.ksp")
        target.extensions.configure(KspExtension::class.java) {
            arg("komapper.enumStrategy", "ordinal")
            arg("komapper.namingStrategy", "UPPER_SNAKE_CASE")
        }
    }
}
Something like that
(To get access to KspExtension you need your build gradle file of your convention plugin module to define the dependency to ksp plugin.)
m

Mohammed Toufeeq Ahamed

09/20/2023, 9:55 AM
Thanks, this really helped. ❤️
y

Yang

09/20/2023, 10:55 AM
You might need to run the configuration block in an afterEvaluate unfortunately
y

Yang

09/21/2023, 2:27 AM
the reason doing this without
afterEvaluate
doesn’t work for me is the value of my args come from a custom plugin extension which uses lazy providers like
val myValue: Property<Boolean>
Because `KspExtension`’s
arg
require the lazy properties to be evaluated eagerly but the values aren’t be available during configuration, the
arg
value is never set, unless I wrap the config block inside an
afterEvaluate
to call the
arg("key", "value")
after the values provided via the custom extension are available.
👍 1
g

glureau

09/21/2023, 7:06 AM
Alright make sense, also hopefully it's not required for the OP, but clearly a gradle trick to keep in mind 👌
4 Views