Skip to content

Commit

Permalink
add kotlin proto info
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Oct 12, 2021
1 parent ae74e3e commit 0a9dc03
Showing 1 changed file with 48 additions and 28 deletions.
76 changes: 48 additions & 28 deletions compiler/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
gRPC Kotlin Codegen Plugin for Protobuf Compiler
================================================

This generates the Kotlin interfaces out of the service definition from a
`.proto` file. It works with the Protobuf Compiler (`protoc`).
This generates the Kotlin interfaces out of the service definition from a`.proto` file. It works with the Protobuf Compiler (`protoc`) and uses a `protoc` plugin to generate Kotlin wrappers for the generated Java classes.
> Note: You can use the gRPC Kotlin compiler without using the protoc Kotlin compiler, but these instructions assume you want to use both together.
### Build Tool Plugins

Expand All @@ -11,38 +11,42 @@ Usually this compiler is used via a build tool plugin, like in Gradle, Maven, et
For Gradle, include the [protobuf plugin](https://github.com/google/protobuf-gradle-plugin) with at least version `0.8.13`, like:
```
plugins {
id("com.google.protobuf") version "SOME_VERSION"
id("com.google.protobuf") version "YOUR_PROTOBUF_PLUGIN_VERSION"
}
```

Add dependencies on `grpc-kotlin-stub` and a protobuf library like:
Add dependencies on `grpc-kotlin-stub` and protobuf libraries like:
```
dependencies {
implementation("io.grpc:grpc-kotlin-stub:SOME_VERSION")
implementation("io.grpc:grpc-protobuf:SOME_VERSION")
implementation("io.grpc:grpc-kotlin-stub:YOUR_GRPC_KOTLIN_VERSION")
implementation("io.grpc:grpc-protobuf:YOUR_GRPC_VERSION")
implementation("com.google.protobuf:protobuf-kotlin:YOUR_PROTOBUF_VERSION")
}
```

Finally, setup the protobuf plugin:
```
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:SOME_VERSION"
artifact = "com.google.protobuf:protoc:YOUR_PROTOBUF_VERSION"
}
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:SOME_VERSION"
artifact = "io.grpc:protoc-gen-grpc-java:YOUR_GRPC_VERSION"
}
id("grpckt") {
artifact = "io.grpc:protoc-gen-grpc-kotlin:SOME_VERSION:jdk7@jar"
artifact = "io.grpc:protoc-gen-grpc-kotlin:YOUR_GRPC_KOTLIN_VERSION:jdk7@jar"
}
}
generateProtoTasks {
ofSourceSet("main").forEach {
all().forEach {
it.plugins {
id("grpc")
id("grpckt")
}
it.builtins {
id("kotlin")
}
}
}
}
Expand All @@ -55,44 +59,60 @@ For Maven, include the [protobuf plugin](https://www.xolstice.org/protobuf-maven
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:SOME_VERSION:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:SOME_VERSION:exe:${os.detected.classifier}</pluginArtifact>
<protocPlugins>
<protocPlugin>
<id>grpc-kotlin</id>
<groupId>io.grpc</groupId>
<artifactId>protoc-gen-grpc-kotlin</artifactId>
<version>SOME_VERSION</version>
<classifier>jdk7</classifier>
<mainClass>io.grpc.kotlin.generator.GeneratorRunner</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:YOUR_PROTOBUF_VERSION:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:YOUR_GRPC_VERSION:exe:${os.detected.classifier}</pluginArtifact>
<protocPlugins>
<protocPlugin>
<id>grpc-kotlin</id>
<groupId>io.grpc</groupId>
<artifactId>protoc-gen-grpc-kotlin</artifactId>
<version>YOUR_GRPC_KOTLIN_VERSION</version>
<classifier>jdk7</classifier>
<mainClass>io.grpc.kotlin.generator.GeneratorRunner</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
</execution>
<execution>
<id>compile-kt</id>
<goals>
<goal>compile-custom</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:YOUR_PROTOBUF_VERSION:exe:${os.detected.classifier}</protocArtifact>
<outputDirectory>${project.build.directory}/generated-sources/protobuf/kotlin</outputDirectory>
<pluginId>kotlin</pluginId>
</configuration>
</execution>
</executions>
</plugin>
```

Make sure you include a dependency on `stub` and a protobuf library like:
Make sure you include a dependency on `stub` and protobuf libraries like:
```
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-kotlin-stub</artifactId>
<version>SOME_VERSION</version>
<version>YOUR_GRPC_KOTLIN_VERSION</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>SOME_VERSION</version>
<version>YOUR_PROTOBUF_VERSION</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-kotlin</artifactId>
<version>YOUR_PROTOBUF_VERSION</version>
</dependency>
```

Expand Down

0 comments on commit 0a9dc03

Please sign in to comment.