From 700e3144b8f24ff1b031cbb42593d3161b95d3b5 Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Thu, 13 Feb 2025 14:39:48 +0100 Subject: [PATCH 1/3] Updated gRPC doc for new Gradle configs --- .../topics/grpc-configuration.topic | 128 ++++++++++++------ 1 file changed, 87 insertions(+), 41 deletions(-) diff --git a/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic b/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic index 5ac509320..3b8953c7f 100644 --- a/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic +++ b/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic @@ -40,8 +40,8 @@

plugins { - kotlin("jvm") version "2.1.0" - kotlin("plugin.serialization") version "2.1.0" + kotlin("jvm") version "%kotlin-version%" + kotlin("plugin.serialization") version "%kotlin-version%" id("org.jetbrains.kotlinx.rpc.plugin") version "<version>" id("com.google.protobuf") version "0.9.4" } @@ -66,65 +66,111 @@

gRPC requires additional code generation from the protoc compiler. - This can be setup up in the following way: + It is set up automatically for you when the com.google.protobuf + plugin is present in the project. +

+

+ We provide additional options for configuration:

- protobuf { - protoc { - artifact = "com.google.protobuf:protoc:4.29.3" - } + rpc { + grpc { + // enforces additional checks on the project configuration + enabled = true - plugins { - create("kotlinx-rpc") { - artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:<version>:all@jar" + // Quick access to a Locator and Options + // for the kotlinx-rpc Protobuf plugin + plugin { + options { + // add/change options + option("debugOutput=myFile.txt") + } + + locator { + // change artifact coordinates, for example + artifact = "some-other:artifact:version" + } } - create("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:1.69.0" + // 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") + } } - create("grpckt") { - artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar" + // access `generateProto` tasks with a filter + tasksMatching { it.isTest }.all { + plugins { + create("cpp") + } + } + } + } + +

+ If you want to, you can still use protobuf extension to access the configuration. + The following is the equivalent for the code above, but 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 { - create("kotlinx-rpc") { - option("debugOutput=protobuf-plugin.log") - option("messageMode=interface") + named(GrpcExtension.LOCATOR_NAME) { + option("debugOutput=myFile.txt") + } + + create("python") + + if (isTest) { + create("cpp") } - create("grpc") - create("grpckt") } } } } +

+ Minimum recommended configuration looks like this: +

+ + rpc { + grpc { + enabled = true + } + } + +

+ By default, four source sets will be generated: +

-
  • - Four source sets will be generated: - -
  • java - protobuf Java declarations
  • -
  • grpc - gRPC Java declarations
  • -
  • grpckt - gRPC Kotlin wrappers for Java
  • -
  • kotlinx-rpc - pur wrappers for all of the above
  • -
    -

    - You won't need to use the first three directly, only the declarations from the kotlinx-rpc - source set are intended to be used. -

    - Source sets are generated into $BUILD_DIR/generated/source/proto/main directory - unless specified otherwise. - -
  • - option("debugOutput=protobuf-plugin.log") lets you specify the file - for the protoc plugin debug output. -
  • -
  • - option("messageMode=interface") is intended to be like so. Don't change it. -
  • +
  • java - protobuf Java declarations
  • +
  • grpc - gRPC Java declarations
  • +
  • grpckt - gRPC Kotlin wrappers for Java
  • +
  • kotlinx-rpc - pur wrappers for all of the above
  • +

    + You won't need to use the first three directly, only the declarations from the kotlinx-rpc + source set are intended to be used. +

    +

    + Source sets are generated into $BUILD_DIR/generated/source/proto/main directory + unless specified otherwise. +

    From 1382c0a78abe6d6e4a60d383b98eb47da923426c Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Thu, 13 Feb 2025 14:42:57 +0100 Subject: [PATCH 2/3] Updated gRPC sample --- samples/grpc-app/build.gradle.kts | 39 ++++--------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/samples/grpc-app/build.gradle.kts b/samples/grpc-app/build.gradle.kts index 9fbfd78cd..4d9f4d488 100644 --- a/samples/grpc-app/build.gradle.kts +++ b/samples/grpc-app/build.gradle.kts @@ -5,7 +5,7 @@ plugins { kotlin("jvm") version "2.1.10" kotlin("plugin.serialization") version "2.1.10" - id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.0-grpc-6" + id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.1-grpc-16" id("com.google.protobuf") version "0.9.4" } @@ -22,42 +22,13 @@ kotlin { } dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.0-grpc-6") + implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.1-grpc-16") implementation("ch.qos.logback:logback-classic:1.5.16") implementation("io.grpc:grpc-netty:1.69.0") } -val buildDirPath: String = project.layout.buildDirectory.get().asFile.absolutePath - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:4.29.3" - } - - plugins { - create("kotlinx-rpc") { - artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:0.5.0-grpc-6:all@jar" - } - - create("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:1.69.0" - } - - create("grpckt") { - artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar" - } - } - - generateProtoTasks { - all().all { - plugins { - create("kotlinx-rpc") { - option("debugOutput=$buildDirPath/protobuf-plugin.log") - option("messageMode=interface") - } - create("grpc") - create("grpckt") - } - } +rpc { + grpc { + enabled = true } } From 790adbdf8051a21706d123087255503490193213 Mon Sep 17 00:00:00 2001 From: Alexander Sysoev Date: Tue, 18 Feb 2025 14:54:33 +0100 Subject: [PATCH 3/3] GH comments --- .../topics/grpc-configuration.topic | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic b/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic index 3b8953c7f..aba2cfd52 100644 --- a/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic +++ b/docs/pages/kotlinx-rpc/topics/grpc-configuration.topic @@ -75,19 +75,19 @@ rpc { grpc { - // enforces additional checks on the project configuration + // Enforce additional checks on the project configuration enabled = true - // Quick access to a Locator and Options + // Quick access to a `Locator` and `Options` // for the kotlinx-rpc Protobuf plugin plugin { options { - // add/change options + // Add or modify options option("debugOutput=myFile.txt") } locator { - // change artifact coordinates, for example + // Override artifact coordinates artifact = "some-other:artifact:version" } } @@ -114,8 +114,8 @@ }

    - If you want to, you can still use protobuf extension to access the configuration. - The following is the equivalent for the code above, but using the protobuf extension: + You can still use protobuf extension to access the configuration. + The following is the equivalent for the above code using the protobuf extension:

    protobuf { @@ -146,7 +146,7 @@ }

    - Minimum recommended configuration looks like this: + The minimum recommended configuration looks like this:

    rpc { @@ -162,14 +162,13 @@
  • java - protobuf Java declarations
  • grpc - gRPC Java declarations
  • grpckt - gRPC Kotlin wrappers for Java
  • -
  • kotlinx-rpc - pur wrappers for all of the above
  • +
  • kotlinx-rpc - our wrappers for all of the above
  • - You won't need to use the first three directly, only the declarations from the kotlinx-rpc - source set are intended to be used. + Only the declarations from the kotlinx-rpc source set are intended to be used.

    - Source sets are generated into $BUILD_DIR/generated/source/proto/main directory + Source sets are generated into the $BUILD_DIR/generated/source/proto/main directory unless specified otherwise.