Skip to content

Commit

Permalink
Support Kotlin-gRPC client CoroutineStub (line#2669)
Browse files Browse the repository at this point in the history
Motivation:

gRPC for Kotlin is actively developed and
[0.1.1](https://github.com/grpc/grpc-kotlin/releases/tag/v0.1.1) has been released last week.

Modifications:

- Allow GrpcClientFactory creating client from CoroutineStub
- Migrate Kotlin example to gRPC-Kotlin

Result:

- Partially fixes line#2662
- You can now run Armeria gRPC client with `gproto*` and gRPC-Kotlin CoroutinStub

Co-authored-by: Gary Lo <gary.lo@airtasker.com>
  • Loading branch information
ikhoon and gary-lo committed May 6, 2020
1 parent e095b69 commit 6ca3314
Show file tree
Hide file tree
Showing 9 changed files with 2,306 additions and 219 deletions.
4 changes: 3 additions & 1 deletion dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ io.grpc:
- io.netty:netty-handler-proxy
- io.netty:netty-transport
- io.netty:netty-tcnative-boringssl-static
grpc-kotlin-stub: { version: &GRPC_KOTLIN_VERSION '0.1.1' }
protoc-gen-grpc-kotlin: { version: *GRPC_KOTLIN_VERSION }

io.micrometer:
micrometer-core:
Expand Down Expand Up @@ -420,7 +422,7 @@ org.jctools:
- from: org.jctools
to: com.linecorp.armeria.internal.shaded.jctools

# If you want to change `org.jetbrains.kotlin:kotlin-allopen` version,
# If you want to change `org.jetbrains.kotlin:kotlin-allopen` version,
# you also need to change `org.jetbrains.kotlin.jvm` version in `build.gradle`.
org.jetbrains.kotlin:
kotlin-allopen: { version: &KOTLIN_VERSION '1.3.71' }
Expand Down
31 changes: 27 additions & 4 deletions examples/grpc-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ buildscript {
plugins {
application
id("org.jetbrains.kotlin.jvm")
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
}

apply(plugin = "org.jlleitschuh.gradle.ktlint")

application {
mainClassName = "example.armeria.grpc.kotlin.MainKt"
}
Expand All @@ -29,8 +28,10 @@ dependencies {
runtimeOnly("org.slf4j:slf4j-simple")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(kotlin("reflect"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("io.grpc:grpc-kotlin-stub")

testImplementation("jakarta.annotation:jakarta.annotation-api")
testImplementation("net.javacrumbs.json-unit:json-unit-fluent")
Expand All @@ -44,3 +45,25 @@ tasks.withType<KotlinCompile> {
freeCompilerArgs = listOf("-Xjsr305=strict", "-java-parameters")
}
}

// TODO(ikhoon): gRPC-Kotlin compiler does not run well in Windows. The generated stub files are added
// intentionally. Remove this once gRPC-Kotlin compiler supports Windows as well.
kotlin {
sourceSets["main"].apply {
kotlin.srcDir("gen-src/main/kotlinGrpc")
}
}

ktlint {
filter {
exclude { element -> element.file.path.contains("gen-src") }
}
}

tasks.clean {
for (path in delete) {
if (path == project.ext["genSrcDir"]) {
delete.remove(path)
}
}
}

Large diffs are not rendered by default.

Loading

0 comments on commit 6ca3314

Please sign in to comment.