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