Configuration
Edit pageLast modified: 18 February 2025Artifacts for gRPC integration are published separately and updated frequently, independent of the main releases.
gRPC integration is available in an experimental state. The artifacts are published separately in our Space repository.
Dependencies configuration
Below is an example of a project setup.
settings.gradle.kts
:
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/krpc/grpc")
}
}
build.gradle.kts
:
plugins {
kotlin("jvm") version "2.1.10"
kotlin("plugin.serialization") version "2.1.10"
id("org.jetbrains.kotlinx.rpc.plugin") version "<version>"
id("com.google.protobuf") version "0.9.4"
}
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/krpc/grpc")
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:<version>")
implementation("ch.qos.logback:logback-classic:1.5.16")
implementation("io.grpc:grpc-netty:1.69.0")
}
Here <version>
comes from the badge above.
warning
The setup has only been tested on
Kotlin/JVM
projects.
Protoc setup
gRPC requires additional code generation from the protoc compiler. It is set up automatically for you when the com.google.protobuf
plugin is present in the project.
We provide additional options for configuration:
rpc {
grpc {
// Enforce additional checks on the project configuration
enabled = true
// Quick access to a `Locator` and `Options`
// for the kotlinx-rpc Protobuf plugin
plugin {
options {
// Add or modify options
option("debugOutput=myFile.txt")
}
locator {
// Override artifact coordinates
artifact = "some-other:artifact:version"
}
}
// same as `plugin`, but for gRPC Java generation
grpcJavaPlugin { ... }
// same as `plugin`, but for gRPC Kotlin generation
grpcKotlinPlugin { ... }
// access `generateProto` tasks
tasks {
plugins {
create("python")
}
}
// access `generateProto` tasks with a filter
tasksMatching { it.isTest }.all {
plugins {
create("cpp")
}
}
}
}
You can still use protobuf
extension to access the configuration. The following is the equivalent for the above code using the protobuf
extension:
protobuf {
plugins {
named(GrpcExtension.LOCATOR_NAME) {
artifact = "some-other:artifact:version"
}
named(GrpcExtension.GRPC_JAVA_LOCATOR_NAME) { ... }
named(GrpcExtension.GRPC_KOTLIN_LOCATOR_NAME) { ... }
}
generateProtoTasks {
all().all {
plugins {
named(GrpcExtension.LOCATOR_NAME) {
option("debugOutput=myFile.txt")
}
create("python")
if (isTest) {
create("cpp")
}
}
}
}
}
The minimum recommended configuration looks like this:
rpc {
grpc {
enabled = true
}
}
By default, four source sets will be generated:
java
- protobuf Java declarationsgrpc
- gRPC Java declarationsgrpckt
- gRPC Kotlin wrappers for Javakotlinx-rpc
- our wrappers for all of the above
Only the declarations from the kotlinx-rpc
source set are intended to be used.
Source sets are generated into the $BUILD_DIR/generated/source/proto/main
directory unless specified otherwise.