Does anyone know what’s a good way to migrate Groo...
# dsl
m
Does anyone know what’s a good way to migrate Groovy Gradle Logic to Gradle Kotlin DSL? For example, I’m a little stuck on this one - even with code completion from Kotlin DSL (which is awesome!) I don’t know how I would migrate this: https://github.com/grpc/grpc-java/blob/master/examples/example-kotlin/build.gradle#L43-L51
g
I don’t have a good way to do that but I did a lot of changes from .gradle to .gradle.kts. Something that helps is to inspect the classes in IntelliJ (sometimes you need to add the correspondent jar in your classpath) and/or use the --task theTaskName to discover the task type to be using (and from there see what we have inside the classes). Some times you can discover for which type the cast need to be done, not sure if is your case but something like this already happened to me.
m
Hmm, I don’t know if I understand. I tried looking into the
ProtobufConfigurator.groovy
file, and I made a little progress:
Copy code
protobuf {
    protobuf.apply {
        protoc(closureOf<Any> {
            // TODO
        })

        plugins(closureOf<Any> {
            // TODO
        })

        generateProtoTasks.all().forEach { task ->
            task.plugins(closureOf<Any> {
                // TODO
            })
        }
    }

}
still I don’t know what types to use in `closureOf`…
g
I don't have certain, but I think kotlin high order functions can do the same as a groovy closure. Something like (input: String) -> Boolean
m
yep, but the documentation on https://docs.gradle.org/current/userguide/kotlin_dsl.html#groovy_closures_from_kotlin states I should use
closureOf
in this case (because the protobuf plugin does not use
Action<T>
)
I think I will pause this for now. But I have to say that this problem is a bummer. Many examples are only written for Groovy Gradle, and there is no automatic conversion like Java -> Kotlin. I can’t recommend the Kotlin DSL if problems like these can be a complete showstopper for concentrating on the task at hand (which is: using the plugin)…
c
To be fair, that is a problem of the plugin in question, not kotlin-dsl. Until grpc is updated to support kotlin-dsl configuration you can just leave it in
*.groovy
. kotlin-dsl vs groovy-dsl is not a zero-sum game.
👍 1