Skip to content

Commit 700e314

Browse files
committed
Updated gRPC doc for new Gradle configs
1 parent ae244f2 commit 700e314

File tree

1 file changed

+87
-41
lines changed

1 file changed

+87
-41
lines changed

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

Lines changed: 87 additions & 41 deletions
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,111 @@
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+
// enforces 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/change options
86+
option("debugOutput=myFile.txt")
87+
}
88+
89+
locator {
90+
// change artifact coordinates, for example
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+
If you want to, you can still use <code>protobuf</code> extension to access the configuration.
118+
The following is the equivalent for the code above, but 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+
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> - pur wrappers for all of the above</li>
128166
</list>
167+
<p>
168+
You won't need to use the first three directly, only the declarations from the <code>kotlinx-rpc</code>
169+
source set are intended to be used.
170+
</p>
171+
<p>
172+
Source sets are generated into <code>$BUILD_DIR/generated/source/proto/main</code> directory
173+
unless specified otherwise.
174+
</p>
129175
</chapter>
130176
</topic>

0 commit comments

Comments
 (0)