Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | plugins { |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 21 | kotlin("jvm") |
| 22 | id("com.ncorti.ktfmt.gradle") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 23 | java |
| 24 | application |
| 25 | } |
| 26 | |
| 27 | repositories { |
| 28 | mavenCentral() |
| 29 | } |
| 30 | |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 31 | val slf4jVersion: String by project |
| 32 | val httpcoreVersion: String by project |
| 33 | val logbackVersion: String by project |
| 34 | val kotlinxCoroutinesJdk8Version: String by project |
Jiayu Liu | 5fdfd0c | 2022-05-09 10:52:26 +0800 | [diff] [blame] | 35 | val cliktVersion: String by project |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 36 | |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 37 | dependencies { |
| 38 | implementation(platform("org.jetbrains.kotlin:kotlin-bom")) |
| 39 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") |
Jiayu Liu | 5fdfd0c | 2022-05-09 10:52:26 +0800 | [diff] [blame] | 40 | // clikt is used to drive command line parsing and validation |
| 41 | implementation("com.github.ajalt.clikt:clikt:$cliktVersion") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 42 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlinxCoroutinesJdk8Version") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 43 | implementation("org.apache.thrift:libthrift:INCLUDED") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 44 | implementation("org.slf4j:slf4j-api:$slf4jVersion") |
| 45 | implementation("org.apache.httpcomponents:httpcore:$httpcoreVersion") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 46 | implementation("ch.qos.logback:logback-classic:$logbackVersion") |
| 47 | testImplementation("org.jetbrains.kotlin:kotlin-test") |
| 48 | testImplementation("org.jetbrains.kotlin:kotlin-test-junit") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Jiayu Liu | ab83ffc | 2022-05-10 01:56:30 +0800 | [diff] [blame^] | 51 | kotlin { |
| 52 | jvmToolchain { |
| 53 | (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(8)) |
| 54 | } |
| 55 | } |
| 56 | |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 57 | tasks { |
| 58 | application { |
| 59 | applicationName = "TestServer" |
| 60 | mainClass.set("org.apache.thrift.test.TestServerKt") |
| 61 | } |
| 62 | |
| 63 | ktfmt { |
| 64 | kotlinLangStyle() |
| 65 | } |
| 66 | |
| 67 | task<Exec>("compileThrift") { |
| 68 | val thriftBin = if (hasProperty("thrift.compiler")) { |
| 69 | file(property("thrift.compiler")) |
| 70 | } else { |
| 71 | project.rootDir.resolve("../../compiler/cpp/thrift") |
| 72 | } |
| 73 | val outputDir = layout.buildDirectory.dir("generated-sources") |
| 74 | doFirst { |
| 75 | mkdir(outputDir) |
| 76 | } |
| 77 | commandLine = listOf( |
| 78 | thriftBin.absolutePath, |
| 79 | "-gen", |
| 80 | "kotlin", |
| 81 | "-out", |
| 82 | outputDir.get().toString(), |
| 83 | project.rootDir.resolve("../../test/ThriftTest.thrift").absolutePath |
| 84 | ) |
| 85 | group = LifecycleBasePlugin.BUILD_GROUP |
| 86 | } |
| 87 | |
| 88 | compileKotlin { |
| 89 | dependsOn("compileThrift") |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | sourceSets["main"].java { |
| 94 | srcDir(layout.buildDirectory.dir("generated-sources")) |
| 95 | } |