|
40 | 40 | </p>
|
41 | 41 | <code-block lang="Kotlin">
|
42 | 42 | 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%" |
45 | 45 | id("org.jetbrains.kotlinx.rpc.plugin") version "<version>"
|
46 | 46 | id("com.google.protobuf") version "0.9.4"
|
47 | 47 | }
|
|
66 | 66 | <p>
|
67 | 67 | gRPC requires additional code generation from the <a href="https://github.com/google/protobuf-gradle-plugin">protoc</a>
|
68 | 68 | 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: |
70 | 74 | </p>
|
71 | 75 | <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 |
76 | 80 |
|
77 |
| - plugins { |
78 |
| - create("kotlinx-rpc") { |
79 |
| - artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:<version>: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 | + } |
80 | 93 | }
|
81 | 94 |
|
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 | + } |
84 | 105 | }
|
85 | 106 |
|
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" |
88 | 125 | }
|
| 126 | + |
| 127 | + named(GrpcExtension.GRPC_JAVA_LOCATOR_NAME) { ... } |
| 128 | + named(GrpcExtension.GRPC_KOTLIN_LOCATOR_NAME) { ... } |
89 | 129 | }
|
90 | 130 |
|
91 | 131 | generateProtoTasks {
|
92 | 132 | all().all {
|
93 | 133 | 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") |
97 | 142 | }
|
98 |
| - create("grpc") |
99 |
| - create("grpckt") |
100 | 143 | }
|
101 | 144 | }
|
102 | 145 | }
|
103 | 146 | }
|
104 | 147 | </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> |
105 | 161 | <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> |
128 | 166 | </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> |
129 | 174 | </chapter>
|
130 | 175 | </topic>
|
0 commit comments