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") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 22 | java |
| 23 | application |
Jiayu Liu | 5b15838 | 2022-05-12 00:20:37 +0800 | [diff] [blame] | 24 | id("com.ncorti.ktfmt.gradle") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 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 httpclientVersion: String by project |
| 33 | val httpcoreVersion: String by project |
| 34 | val logbackVersion: String by project |
| 35 | val kotlinxCoroutinesJdk8Version: String by project |
Jiayu Liu | 5fdfd0c | 2022-05-09 10:52:26 +0800 | [diff] [blame] | 36 | val cliktVersion: String by project |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 37 | |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 38 | dependencies { |
| 39 | implementation(platform("org.jetbrains.kotlin:kotlin-bom")) |
| 40 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") |
Jiayu Liu | 5fdfd0c | 2022-05-09 10:52:26 +0800 | [diff] [blame] | 41 | // clikt is used to drive command line parsing and validation |
| 42 | implementation("com.github.ajalt.clikt:clikt:$cliktVersion") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 43 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlinxCoroutinesJdk8Version") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 44 | implementation("org.apache.thrift:libthrift:INCLUDED") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 45 | implementation("org.slf4j:slf4j-api:$slf4jVersion") |
| 46 | implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") |
| 47 | implementation("org.apache.httpcomponents:httpcore:$httpcoreVersion") |
Jiayu Liu | eb62fa8 | 2022-05-08 13:01:41 +0800 | [diff] [blame] | 48 | implementation("ch.qos.logback:logback-classic:$logbackVersion") |
| 49 | testImplementation("org.jetbrains.kotlin:kotlin-test") |
| 50 | testImplementation("org.jetbrains.kotlin:kotlin-test-junit") |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Jiayu Liu | ab83ffc | 2022-05-10 01:56:30 +0800 | [diff] [blame] | 53 | kotlin { |
| 54 | jvmToolchain { |
Jiayu Liu | 166a213 | 2023-08-10 06:33:43 +0800 | [diff] [blame^] | 55 | (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(8)) |
Jiayu Liu | ab83ffc | 2022-05-10 01:56:30 +0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 59 | tasks { |
| 60 | application { |
| 61 | applicationName = "TestClient" |
| 62 | mainClass.set("org.apache.thrift.test.TestClientKt") |
| 63 | } |
| 64 | |
Jiayu Liu | 5b15838 | 2022-05-12 00:20:37 +0800 | [diff] [blame] | 65 | if (JavaVersion.current().isJava11Compatible) { |
| 66 | ktfmt { |
| 67 | kotlinLangStyle() |
| 68 | } |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | task<Exec>("compileThrift") { |
| 72 | val thriftBin = if (hasProperty("thrift.compiler")) { |
Jiayu Liu | a4e1136 | 2023-07-05 08:32:55 +0000 | [diff] [blame] | 73 | file(property("thrift.compiler")!!) |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 74 | } else { |
| 75 | project.rootDir.resolve("../../compiler/cpp/thrift") |
| 76 | } |
| 77 | val outputDir = layout.buildDirectory.dir("generated-sources") |
| 78 | doFirst { |
| 79 | mkdir(outputDir) |
| 80 | } |
| 81 | commandLine = listOf( |
| 82 | thriftBin.absolutePath, |
| 83 | "-gen", |
| 84 | "kotlin", |
| 85 | "-out", |
| 86 | outputDir.get().toString(), |
| 87 | project.rootDir.resolve("../../test/ThriftTest.thrift").absolutePath |
| 88 | ) |
| 89 | group = LifecycleBasePlugin.BUILD_GROUP |
| 90 | } |
| 91 | |
| 92 | compileKotlin { |
| 93 | dependsOn("compileThrift") |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | sourceSets["main"].java { |
| 98 | srcDir(layout.buildDirectory.dir("generated-sources")) |
| 99 | } |