Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +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 | */ |
thomasbruggink | 5d0205d | 2024-11-05 15:33:18 +0900 | [diff] [blame] | 19 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
| 20 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 21 | |
| 22 | plugins { |
| 23 | kotlin("jvm") |
| 24 | id("com.ncorti.ktfmt.gradle") |
| 25 | } |
| 26 | |
| 27 | repositories { |
| 28 | mavenCentral() |
| 29 | } |
| 30 | |
| 31 | dependencies { |
| 32 | implementation(platform("org.jetbrains.kotlin:kotlin-bom")) |
| 33 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") |
dependabot[bot] | bf57082 | 2024-10-01 03:44:07 -0400 | [diff] [blame] | 34 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.9.0") |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 35 | implementation("org.apache.thrift:libthrift:INCLUDED") |
| 36 | testImplementation(kotlin("test")) |
| 37 | } |
| 38 | |
Jiayu Liu | ab83ffc | 2022-05-10 01:56:30 +0800 | [diff] [blame] | 39 | kotlin { |
| 40 | jvmToolchain { |
thomasbruggink | 5d0205d | 2024-11-05 15:33:18 +0900 | [diff] [blame] | 41 | languageVersion.set(JavaLanguageVersion.of(17)) |
Jiayu Liu | ab83ffc | 2022-05-10 01:56:30 +0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
thomasbruggink | 5d0205d | 2024-11-05 15:33:18 +0900 | [diff] [blame] | 45 | java { |
| 46 | sourceCompatibility = JavaVersion.VERSION_1_8 |
| 47 | targetCompatibility = JavaVersion.VERSION_1_8 |
| 48 | } |
| 49 | |
| 50 | tasks.withType<KotlinCompile> { |
Christopher Tubbs | 8922f17 | 2024-09-17 20:42:24 -0400 | [diff] [blame] | 51 | compilerOptions { |
thomasbruggink | 5d0205d | 2024-11-05 15:33:18 +0900 | [diff] [blame] | 52 | jvmTarget = JvmTarget.JVM_1_8 |
| 53 | freeCompilerArgs = listOf("-Xjdk-release=1.8") |
Christopher Tubbs | 8922f17 | 2024-09-17 20:42:24 -0400 | [diff] [blame] | 54 | } |
Fokko Driesprong | 0b14a1b | 2023-04-14 11:06:15 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 57 | tasks { |
Jiayu Liu | 5b15838 | 2022-05-12 00:20:37 +0800 | [diff] [blame] | 58 | if (JavaVersion.current().isJava11Compatible) { |
| 59 | ktfmt { |
| 60 | kotlinLangStyle() |
| 61 | } |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | test { |
| 65 | useJUnitPlatform() |
| 66 | } |
| 67 | |
| 68 | task<Exec>("compileThrift") { |
| 69 | val thriftBin = if (hasProperty("thrift.compiler")) { |
Jiayu Liu | a4e1136 | 2023-07-05 08:32:55 +0000 | [diff] [blame] | 70 | file(property("thrift.compiler")!!) |
Jiayu Liu | 6c002b6 | 2022-05-07 00:40:03 +0800 | [diff] [blame] | 71 | } else { |
| 72 | project.rootDir.resolve("../../compiler/cpp/thrift") |
| 73 | } |
| 74 | val outputDir = layout.buildDirectory.dir("generated-sources") |
| 75 | doFirst { |
| 76 | mkdir(outputDir) |
| 77 | } |
| 78 | commandLine = listOf( |
| 79 | thriftBin.absolutePath, |
| 80 | "-gen", |
| 81 | "kotlin", |
| 82 | "-out", |
| 83 | outputDir.get().toString(), |
| 84 | layout.projectDirectory.file("src/test/resources/AnnotationTest.thrift").asFile.absolutePath |
| 85 | ) |
| 86 | group = LifecycleBasePlugin.BUILD_GROUP |
| 87 | } |
| 88 | |
| 89 | compileKotlin { |
| 90 | dependsOn("compileThrift") |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | sourceSets["main"].java { |
| 95 | srcDir(layout.buildDirectory.dir("generated-sources")) |
| 96 | } |