|
| 1 | +import com.google.protobuf.gradle.generateProtoTasks |
| 2 | +import com.google.protobuf.gradle.id |
| 3 | +import com.google.protobuf.gradle.ofSourceSet |
| 4 | +import com.google.protobuf.gradle.plugins |
| 5 | +import com.google.protobuf.gradle.protobuf |
| 6 | +import com.google.protobuf.gradle.protoc |
| 7 | + |
| 8 | +val grpcVersion = "1.30.0" |
| 9 | +val grpcKotlinVersion = "0.1.3" |
| 10 | +val protobufVersion = "3.12.2" |
| 11 | +val coroutinesVersion = "1.3.7" |
| 12 | + |
| 13 | +plugins { |
| 14 | + application |
| 15 | + kotlin("jvm") version "1.3.72" |
| 16 | + id("com.google.protobuf") version "0.8.12" |
| 17 | + id("org.jlleitschuh.gradle.ktlint") version "9.2.1" |
| 18 | +} |
| 19 | + |
| 20 | +repositories { |
| 21 | + mavenLocal() |
| 22 | + google() |
| 23 | + jcenter() |
| 24 | + mavenCentral() |
| 25 | +} |
| 26 | + |
| 27 | +dependencies { |
| 28 | + implementation(kotlin("stdlib")) |
| 29 | + implementation("javax.annotation:javax.annotation-api:1.2") |
| 30 | + implementation("com.google.protobuf:protobuf-java-util:$protobufVersion") |
| 31 | + implementation("io.grpc:grpc-protobuf:$grpcVersion") |
| 32 | + implementation("io.grpc:grpc-stub:$grpcVersion") |
| 33 | + implementation("io.grpc:grpc-kotlin-stub:$grpcKotlinVersion") |
| 34 | + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") |
| 35 | + runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") |
| 36 | +} |
| 37 | + |
| 38 | +protobuf { |
| 39 | + protoc { |
| 40 | + artifact = "com.google.protobuf:protoc:$protobufVersion" |
| 41 | + } |
| 42 | + plugins { |
| 43 | + id("grpc") { |
| 44 | + artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion" |
| 45 | + } |
| 46 | + id("grpckt") { |
| 47 | + artifact = "io.grpc:protoc-gen-grpc-kotlin:$grpcKotlinVersion" |
| 48 | + } |
| 49 | + } |
| 50 | + generateProtoTasks { |
| 51 | + ofSourceSet("main").forEach { |
| 52 | + it.plugins { |
| 53 | + id("grpc") |
| 54 | + id("grpckt") |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +java { |
| 61 | + sourceCompatibility = JavaVersion.VERSION_1_8 |
| 62 | +} |
| 63 | + |
| 64 | +application { |
| 65 | + mainClassName = "io.grpc.examples.helloworld.HelloWorldServerKt" |
| 66 | +} |
| 67 | + |
| 68 | +tasks.register<JavaExec>("HelloWorldServer") { |
| 69 | + dependsOn("classes") |
| 70 | + classpath = sourceSets["main"].runtimeClasspath |
| 71 | + main = "io.grpc.examples.helloworld.HelloWorldServerKt" |
| 72 | +} |
| 73 | + |
| 74 | +tasks.register<JavaExec>("HelloWorldClient") { |
| 75 | + dependsOn("classes") |
| 76 | + classpath = sourceSets["main"].runtimeClasspath |
| 77 | + main = "io.grpc.examples.helloworld.HelloWorldClientKt" |
| 78 | +} |
| 79 | + |
| 80 | +tasks.register<JavaExec>("RouteGuideServerKt") { |
| 81 | + dependsOn("classes") |
| 82 | + classpath = sourceSets["main"].runtimeClasspath |
| 83 | + main = "io.grpc.examples.routeguide.RouteGuideServerKt" |
| 84 | +} |
| 85 | + |
| 86 | +tasks.register<JavaExec>("RouteGuideClientKt") { |
| 87 | + dependsOn("classes") |
| 88 | + classpath = sourceSets["main"].runtimeClasspath |
| 89 | + main = "io.grpc.examples.routeguide.RouteGuideClientKt" |
| 90 | +} |
| 91 | + |
| 92 | +val helloWorldServerStartScripts = tasks.register<CreateStartScripts>("helloWorldServerStartScripts") { |
| 93 | + mainClassName = "io.grpc.examples.helloworld.HelloWorldServerKt" |
| 94 | + applicationName = "hello-world-server" |
| 95 | + outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir |
| 96 | + classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath |
| 97 | +} |
| 98 | + |
| 99 | +val helloWorldClientStartScripts = tasks.register<CreateStartScripts>("helloWorldClientStartScripts") { |
| 100 | + mainClassName = "io.grpc.examples.helloworld.HelloWorldClientKt" |
| 101 | + applicationName = "hello-world-client" |
| 102 | + outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir |
| 103 | + classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath |
| 104 | +} |
| 105 | + |
| 106 | +val routeGuideServerStartScripts = tasks.register<CreateStartScripts>("routeGuideServerStartScripts") { |
| 107 | + mainClassName = "io.grpc.examples.routeguide.RouteGuideServerKt" |
| 108 | + applicationName = "route-guide-server" |
| 109 | + outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir |
| 110 | + classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath |
| 111 | +} |
| 112 | + |
| 113 | +val routeGuideClientStartScripts = tasks.register<CreateStartScripts>("routeGuideClientStartScripts") { |
| 114 | + mainClassName = "io.grpc.examples.routeguide.RouteGuideClientKt" |
| 115 | + applicationName = "route-guide-client" |
| 116 | + outputDir = tasks.named<CreateStartScripts>("startScripts").get().outputDir |
| 117 | + classpath = tasks.named<CreateStartScripts>("startScripts").get().classpath |
| 118 | +} |
| 119 | + |
| 120 | +tasks.named("startScripts") { |
| 121 | + dependsOn(helloWorldServerStartScripts) |
| 122 | + dependsOn(helloWorldClientStartScripts) |
| 123 | + dependsOn(routeGuideServerStartScripts) |
| 124 | + dependsOn(routeGuideClientStartScripts) |
| 125 | +} |
0 commit comments