Skip to content

Commit c7f4174

Browse files
authored
Update gRPC Docs and Sample (#284)
* Updated gRPC doc for new Gradle configs * Updated gRPC sample * GH comments
1 parent bdfb6fd commit c7f4174

File tree

2 files changed

+91
-75
lines changed

2 files changed

+91
-75
lines changed

docs/pages/kotlinx-rpc/topics/grpc-configuration.topic

+86-41
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
</p>
4141
<code-block lang="Kotlin">
4242
plugins {
43-
kotlin("jvm") version "2.1.0"
44-
kotlin("plugin.serialization") version "2.1.0"
43+
kotlin("jvm") version "%kotlin-version%"
44+
kotlin("plugin.serialization") version "%kotlin-version%"
4545
id("org.jetbrains.kotlinx.rpc.plugin") version "&lt;version&gt;"
4646
id("com.google.protobuf") version "0.9.4"
4747
}
@@ -66,65 +66,110 @@
6666
<p>
6767
gRPC requires additional code generation from the <a href="https://github.com/google/protobuf-gradle-plugin">protoc</a>
6868
compiler.
69-
This can be setup up in the following way:
69+
It is set up automatically for you when the <code>com.google.protobuf</code>
70+
plugin is present in the project.
71+
</p>
72+
<p>
73+
We provide additional options for configuration:
7074
</p>
7175
<code-block lang="Kotlin">
72-
protobuf {
73-
protoc {
74-
artifact = "com.google.protobuf:protoc:4.29.3"
75-
}
76+
rpc {
77+
grpc {
78+
// Enforce additional checks on the project configuration
79+
enabled = true
7680

77-
plugins {
78-
create("kotlinx-rpc") {
79-
artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:&lt;version&gt;:all@jar"
81+
// Quick access to a `Locator` and `Options`
82+
// for the kotlinx-rpc Protobuf plugin
83+
plugin {
84+
options {
85+
// Add or modify options
86+
option("debugOutput=myFile.txt")
87+
}
88+
89+
locator {
90+
// Override artifact coordinates
91+
artifact = "some-other:artifact:version"
92+
}
8093
}
8194

82-
create("grpc") {
83-
artifact = "io.grpc:protoc-gen-grpc-java:1.69.0"
95+
// same as `plugin`, but for gRPC Java generation
96+
grpcJavaPlugin { ... }
97+
// same as `plugin`, but for gRPC Kotlin generation
98+
grpcKotlinPlugin { ... }
99+
100+
// access `generateProto` tasks
101+
tasks {
102+
plugins {
103+
create("python")
104+
}
84105
}
85106

86-
create("grpckt") {
87-
artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
107+
// access `generateProto` tasks with a filter
108+
tasksMatching { it.isTest }.all {
109+
plugins {
110+
create("cpp")
111+
}
112+
}
113+
}
114+
}
115+
</code-block>
116+
<p>
117+
You can still use <code>protobuf</code> extension to access the configuration.
118+
The following is the equivalent for the above code using the <code>protobuf</code> extension:
119+
</p>
120+
<code-block lang="Kotlin">
121+
protobuf {
122+
plugins {
123+
named(GrpcExtension.LOCATOR_NAME) {
124+
artifact = "some-other:artifact:version"
88125
}
126+
127+
named(GrpcExtension.GRPC_JAVA_LOCATOR_NAME) { ... }
128+
named(GrpcExtension.GRPC_KOTLIN_LOCATOR_NAME) { ... }
89129
}
90130

91131
generateProtoTasks {
92132
all().all {
93133
plugins {
94-
create("kotlinx-rpc") {
95-
option("debugOutput=protobuf-plugin.log")
96-
option("messageMode=interface")
134+
named(GrpcExtension.LOCATOR_NAME) {
135+
option("debugOutput=myFile.txt")
136+
}
137+
138+
create("python")
139+
140+
if (isTest) {
141+
create("cpp")
97142
}
98-
create("grpc")
99-
create("grpckt")
100143
}
101144
}
102145
}
103146
}
104147
</code-block>
148+
<p>
149+
The minimum recommended configuration looks like this:
150+
</p>
151+
<code-block lang="Kotlin">
152+
rpc {
153+
grpc {
154+
enabled = true
155+
}
156+
}
157+
</code-block>
158+
<p>
159+
By default, four source sets will be generated:
160+
</p>
105161
<list>
106-
<li>
107-
Four source sets will be generated:
108-
<list>
109-
<li><code>java</code> - protobuf Java declarations</li>
110-
<li><code>grpc</code> - gRPC Java declarations</li>
111-
<li><code>grpckt</code> - gRPC Kotlin wrappers for Java</li>
112-
<li><code>kotlinx-rpc</code> - pur wrappers for all of the above</li>
113-
</list>
114-
<p>
115-
You won't need to use the first three directly, only the declarations from the <code>kotlinx-rpc</code>
116-
source set are intended to be used.
117-
</p>
118-
Source sets are generated into <code>$BUILD_DIR/generated/source/proto/main</code> directory
119-
unless specified otherwise.
120-
</li>
121-
<li>
122-
<code>option("debugOutput=protobuf-plugin.log")</code> lets you specify the file
123-
for the <code>protoc</code> plugin debug output.
124-
</li>
125-
<li>
126-
<code>option("messageMode=interface")</code> is intended to be like so. Don't change it.
127-
</li>
162+
<li><code>java</code> - protobuf Java declarations</li>
163+
<li><code>grpc</code> - gRPC Java declarations</li>
164+
<li><code>grpckt</code> - gRPC Kotlin wrappers for Java</li>
165+
<li><code>kotlinx-rpc</code> - our wrappers for all of the above</li>
128166
</list>
167+
<p>
168+
Only the declarations from the <code>kotlinx-rpc</code> source set are intended to be used.
169+
</p>
170+
<p>
171+
Source sets are generated into the <code>$BUILD_DIR/generated/source/proto/main</code> directory
172+
unless specified otherwise.
173+
</p>
129174
</chapter>
130175
</topic>

samples/grpc-app/build.gradle.kts

+5-34
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
plugins {
66
kotlin("jvm") version "2.1.10"
77
kotlin("plugin.serialization") version "2.1.10"
8-
id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.0-grpc-6"
8+
id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.1-grpc-16"
99
id("com.google.protobuf") version "0.9.4"
1010
}
1111

@@ -22,42 +22,13 @@ kotlin {
2222
}
2323

2424
dependencies {
25-
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.0-grpc-6")
25+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.1-grpc-16")
2626
implementation("ch.qos.logback:logback-classic:1.5.16")
2727
implementation("io.grpc:grpc-netty:1.69.0")
2828
}
2929

30-
val buildDirPath: String = project.layout.buildDirectory.get().asFile.absolutePath
31-
32-
protobuf {
33-
protoc {
34-
artifact = "com.google.protobuf:protoc:4.29.3"
35-
}
36-
37-
plugins {
38-
create("kotlinx-rpc") {
39-
artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:0.5.0-grpc-6:all@jar"
40-
}
41-
42-
create("grpc") {
43-
artifact = "io.grpc:protoc-gen-grpc-java:1.69.0"
44-
}
45-
46-
create("grpckt") {
47-
artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
48-
}
49-
}
50-
51-
generateProtoTasks {
52-
all().all {
53-
plugins {
54-
create("kotlinx-rpc") {
55-
option("debugOutput=$buildDirPath/protobuf-plugin.log")
56-
option("messageMode=interface")
57-
}
58-
create("grpc")
59-
create("grpckt")
60-
}
61-
}
30+
rpc {
31+
grpc {
32+
enabled = true
6233
}
6334
}

0 commit comments

Comments
 (0)