google / protobuf-gradle-plugin

Protobuf Plugin for Gradle
Other
1.73k stars 269 forks source link

Example/documentation for generating kotlin classes with kotlin DSL #753

Open pgalbraith opened 2 months ago

pgalbraith commented 2 months ago

I gleamed bits of information here and there that lead me to think it should be possible to get kotlin sources generated using a kotlin builtin, but I haven't had any luck actually accomplishing this. It would be nice to have a documented example of how to do this (kotlin DSL preferably).

pgalbraith commented 2 months ago

I think I have it working now with this protobuf block in a kotlin DSL gradle script::

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:$protobufVersion"
    }

    generateProtoTasks {
        all().forEach {
            it.builtins {
                register("kotlin")
            }
        }
    }
}