kotlin-protobuf 0.6.0 indexed Protocol Buffer generator enables serialization and deserialization across platforms, supporting GRPC, JSON format, and various data types. Integrates with kotlinx-serialization for efficient message handling.
Bring this to kpkg
This library is indexed from the KMP ecosystem and already resolves through kpkg.dev's Maven Central proxy. Maintainers can verify the namespace and publish future versions to kpkg for free hosting, real download stats, and signed-provenance pages.
Publishing coming soonMetadata
Owner jdekim43
Stars 5
Used by 2 libs
Health —
License Apache License 2.0
Latest 0.6.0
Repository github.com/jdekim43/kotlin-protobuf
Updated 2024-12-10 Readme Changelog Kotlin Protobuf
Protocol Buffer generator for kotlin multiplatform or single platform.
Overview
Features
Support data types
optional, repeated, map, oneof features
Support service type (grpc)
Support JSON format
Export type registry
google.api (Grpc Gateway)
Plugin
kotlinx-serialization adapter (You can use protobuf serializer with ProtobufFormat)
Backlog
Gradle Plugin
Customize generating files for Extension (e.g. Modify field type)
Note
This will use 'package' option in proto file. (Not using java_package or other option)
Examples
Usage
Gradle :: JVM
build.gradle.kts
Gradle :: Multiplatform
build.gradle.kts
Options
Set prefix to type url : kotlin-protobuf.prefix=[some_prefix]
Generate TypeRegistry : kotlin-protobuf.type_registry=[output class]
Generate JvmTypeRegistry : kotlin-protobuf.jvm_type_registry=[output class]
Generate Kotlinx SerializersModules : kotlin-protobuf.serializers_modules=[output class]
Note
Option value can't have ','.
How to apply options
protobuf {
...
generateProtoTasks {
all ().forEach {
it.plugins {
id (...) {
option ("[option string]")
}
}
}
}
}
Add option infos of protobuf to generated files. Utilities
ProtobufMessage.toAny : optimize toAny usage
Improve kotlin type mapping
google.protobuf.Any to kotlin.Any
google.protobuf.Empty to kotlin.Unit
some prebuilt types
Kotlinx serialization annotations
Kotlin/JS
Kotlin/Native
Plain kotlin serializer
Grpc Web plugins {
kotlin("jvm" ) version "1.9.23"
kotlin("plugin.serialization" ) version "1.9.23" //optional
id ("com.google.protobuf" ) version "0.9.4"
}
sourceSets {
main {
proto {
srcDir(File(project.projectDir, "src/main/proto" ))
}
}
}
protobuf {
plugins {
//If you want without kotlinx-serialization.
//id("kotlin-protobuf-kotlin" ) {
// artifact = "kr.jadekim:kotlin-protobuf-generator:$kotlinProtobufVersion "
//}
id ("kotlin-protobuf-kotlinx" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-kotlinx:$kotlinProtobufVersion "
}
id ("kotlin-protobuf-converter-jvm" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-converter-jvm:$kotlinProtobufVersion "
}
id ("grpc" ) {
artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion "
}
id ("kotlin-protobuf-grpc-jvm" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-grpc-jvm:$kotlinProtobufVersion "
}
}
generateProtoTasks {
all().forEach {
it.plugins {
id ("kotlin-protobuf-kotlinx" )
id ("kotlin-protobuf-converter-jvm" )
id ("grpc" )
id ("kotlin-protobuf-grpc-jvm" )
}
}
}
}
dependencies {
implementation("kr.jadekim:kotlin-protobuf:$kotlinProtobufVersion " )
implementation("kr.jadekim:kotlin-protobuf-kotlinx:$kotlinProtobufVersion " )
implementation("kr.jadekim:kotlin-protobuf-grpc:$kotlinProtobufVersion " )
implementation("com.google.protobuf:protobuf-java:$protobufVersion " )
implementation("io.grpc:grpc-protobuf:$grpcVersion " )
implementation("io.grpc:grpc-stub:$grpcVersion " )
implementation("io.grpc:grpc-kotlin-stub:$grpcKotlinVersion " )
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion " )
}
plugins {
kotlin("multiplatform" ) version "1.9.23"
kotlin("plugin.serialization" ) version "1.9.23" //optional
id ("com.google.protobuf" ) version "0.9.4"
`java-library`
}
sourceSets {
main {
proto {
srcDir(File(project.projectDir, "src/main/proto" ))
}
}
}
protobuf {
plugins {
//If you want without kotlinx-serialization.
//id("kotlin-protobuf-kotlin" ) {
// artifact = "kr.jadekim:kotlin-protobuf-generator:$kotlinProtobufVersion "
//}
id ("kotlin-protobuf-kotlinx" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-kotlinx:$kotlinProtobufVersion "
}
id ("kotlin-protobuf-converter-multiplatform" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-multiplatform:$kotlinProtobufVersion "
}
id ("kotlin-protobuf-converter-multiplatform-jvm" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-multiplatform-jvm:$kotlinProtobufVersion "
}
id ("grpc" ) {
artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion "
}
id ("kotlin-protobuf-grpc-multiplatform" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-grpc-multiplatform:$kotlinProtobufVersion "
}
id ("kotlin-protobuf-grpc-multiplatform-jvm" ) {
artifact = "kr.jadekim:kotlin-protobuf-generator-grpc-multiplatform-jvm:$kotlinProtobufVersion "
}
}
generateProtoTasks {
all().forEach {
it.plugins {
id ("kotlin-protobuf-kotlinx" )
id ("kotlin-protobuf-converter-multiplatform" )
id ("kotlin-protobuf-converter-multiplatform-jvm" )
id ("grpc" )
id ("kotlin-protobuf-grpc-multiplatform" )
id ("kotlin-protobuf-grpc-multiplatform-jvm" )
}
}
}
}
kotlin {
jvm {
withJava()
}
sourceSets {
val commonMain by getting {
kotlin.srcDir(File(buildDir, "generated/source/proto/main/kotlin-protobuf-kotlinx" ))
kotlin.srcDir(File(buildDir, "generated/source/proto/main/kotlin-protobuf-converter-multiplatform" ))
kotlin.srcDir(File(buildDir, "generated/source/proto/main/kotlin-protobuf-grpc-multiplatform" ))
dependencies {
implementation("kr.jadekim:kotlin-protobuf:$kotlinProtobufVersion " )
implementation("kr.jadekim:kotlin-protobuf-kotlinx:$kotlinProtobufVersion " )
implementation("kr.jadekim:kotlin-protobuf-grpc:$kotlinProtobufVersion " )
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion " )
}
}
val jvmMain by getting {
kotlin.srcDir(File(buildDir, "generated/source/proto/main/java" ))
kotlin.srcDir(File(buildDir, "generated/source/proto/main/grpc" ))
kotlin.srcDir(File(buildDir, "generated/source/proto/main/kotlin-protobuf-converter-multiplatform-jvm" ))
kotlin.srcDir(File(buildDir, "generated/source/proto/main/kotlin-protobuf-grpc-multiplatform-jvm" ))
dependencies {
implementation("com.google.protobuf:protobuf-java:$protobufVersion " )
implementation("io.grpc:grpc-protobuf:$grpcVersion " )
implementation("io.grpc:grpc-stub:$grpcVersion " )
implementation("io.grpc:grpc-kotlin-stub:$grpcKotlinVersion " )
}
}
}
}
Related libraries Surfaced from shared tags and platforms — no rankings paid for.
protokt ★ 166
open-toast Creates and compiles protocol buffer definitions with a concise builder DSL, supports custom wrapper types, interface implementation, and gRPC code generation. Offers a seamless integration for serialized data handling and high-performance operations. Shared: serializer, serialization, rpc GRPC-Kotlin-Multiplatform ★ 133
TimOrtel Implements client-side gRPC with support for parsing proto3 files, generating corresponding code, and suspending RPC calls. Features a DSL for creating proto objects and supports various proto types. Shared: web, rpc, kotlin-native elasticmagic-kt ★ 46
anti-social Asynchronous Elasticsearch query DSL enabling typed query expressions, sub-field navigation, and declarative query modifications. Supports multiple serialization libraries and autodetects Elasticsearch and Opensearch versions. Shared: web, serializer, serialization kotlin-fhir ★ 63
ohs-foundation Lean, fast HL7 FHIR data-model implementation with minimal generated classes, JSON-only serialization, multi-version support, and a tiny runtime footprint for efficient healthcare data handling. Shared: web, serialization, kotlin-native kotlin.document.store ★ 44
lamba92 Fast NoSql document store for managing JSON objects with typed and schemaless data. Features developer-friendly APIs, asynchronous operations, indexing, and extensibility for custom serializers or storage backends. Shared: web, serializer, kotlin-serialization kotlinx-serialization-csv ★ 38
hfhbd Serialize and deserialize ordered CSV and Fixed Length Format Files, leveraging a specific serialization library. Supports multiple platforms and offers easy integration via MavenCentral. Shared: serializer, serialization, kotlin-serialization