Skip to content

Protobuf Kotlin Dataclass, Converter & Custom Kotlin Coroutine gRPC Generator

License

Notifications You must be signed in to change notification settings

mscheong01/krotoDC

Repository files navigation

krotoDC

krotoDC is a protoc plugin for generating Kotlin data classes and gRPC service/stub from a .proto input. This library makes it easy to work with Protocol Buffers and gRPC in your Kotlin projects.

check out my blog post that introduces krotoDC

Features

  • Generates Kotlin data classes from .proto files

  • Generates Converter extension methods between generated classes and GeneratedMessageV3 classes

  • Generates gRPC service/stub based on the service definition in .proto files

  • Supports Kotlin specific features like nullable fields and sealed oneof classes:

    see the generated code spec here

Installation

In your project's build.gradle.kts file, add the following dependencies:

dependencies {
    implementation("com.google.protobuf:protobuf-java:3.25.3")
    implementation("com.google.protobuf:protobuf-java-util:3.25.3")
    implementation("io.grpc:grpc-stub:1.61.1")
    implementation("io.grpc:grpc-kotlin-stub:1.4.1")
    implementation("io.github.mscheong01:krotoDC-core:1.1.1")
}

Usage

  1. Configure the protobuf plugin in your build.gradle.kts file:
protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.25.3"
    }
    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java:1.61.1"
        }
        id("krotoDC") {
            artifact = "io.github.mscheong01:protoc-gen-krotoDC:1.1.1:jdk8@jar"
        }
    }
    generateProtoTasks {
        all().forEach {
            it.plugins {
                id("grpc")
                id("krotoDC")
            }
        }
    }
}
  1. Create your .proto files with your message and service definitions.

  2. Build your project, and the plugin will generate Kotlin data classes and gRPC service/stub based on the .proto files.

Snapshot Versions

krotoDC provides snapshot versions that are automatically released when changes are pushed to the main branch. The current snapshot version is the next minor version of the current release version with a -SNAPSHOT suffix. For example, if the current release is 1.2.3, the snapshot version will be 1.3.0-SNAPSHOT.

To use snapshot versions, add the maven snapshot repository to your build configuration

repositories {
    maven {
        url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
    }
}

Contributing

Contributions are welcome! Please see our contributing guidelines for more information.

License

This project is licensed under the Apache 2.0 License.

About

Protobuf Kotlin Dataclass, Converter & Custom Kotlin Coroutine gRPC Generator

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages