blob: 81203af191cfea7d7e0147a5febce58ef790fd0d [file] [log] [blame]
Jiayu Liu6c002b62022-05-07 00:40:03 +08001/*
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 */
thomasbruggink5d0205d2024-11-05 15:33:18 +090019import org.jetbrains.kotlin.gradle.dsl.JvmTarget
20import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Jiayu Liu6c002b62022-05-07 00:40:03 +080021
22plugins {
23 kotlin("jvm")
24 id("com.ncorti.ktfmt.gradle")
25}
26
dependabot[bot]5501e8f2025-09-05 16:37:40 -040027repositories { mavenCentral() }
Jiayu Liu6c002b62022-05-07 00:40:03 +080028
29dependencies {
30 implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
31 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
dependabot[bot]9e7be1d2025-05-01 06:14:07 +000032 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.10.2")
Jiayu Liu6c002b62022-05-07 00:40:03 +080033 implementation("org.apache.thrift:libthrift:INCLUDED")
34 testImplementation(kotlin("test"))
35}
36
dependabot[bot]5501e8f2025-09-05 16:37:40 -040037kotlin { jvmToolchain { languageVersion.set(JavaLanguageVersion.of(17)) } }
Jiayu Liuab83ffc2022-05-10 01:56:30 +080038
thomasbruggink5d0205d2024-11-05 15:33:18 +090039java {
40 sourceCompatibility = JavaVersion.VERSION_1_8
41 targetCompatibility = JavaVersion.VERSION_1_8
42}
43
44tasks.withType<KotlinCompile> {
Christopher Tubbs8922f172024-09-17 20:42:24 -040045 compilerOptions {
thomasbruggink5d0205d2024-11-05 15:33:18 +090046 jvmTarget = JvmTarget.JVM_1_8
47 freeCompilerArgs = listOf("-Xjdk-release=1.8")
Christopher Tubbs8922f172024-09-17 20:42:24 -040048 }
Fokko Driesprong0b14a1b2023-04-14 11:06:15 +020049}
50
Jiayu Liu6c002b62022-05-07 00:40:03 +080051tasks {
Jiayu Liu5b158382022-05-12 00:20:37 +080052 if (JavaVersion.current().isJava11Compatible) {
dependabot[bot]5501e8f2025-09-05 16:37:40 -040053 ktfmt { kotlinLangStyle() }
Jiayu Liu6c002b62022-05-07 00:40:03 +080054 }
55
dependabot[bot]5501e8f2025-09-05 16:37:40 -040056 test { useJUnitPlatform() }
Jiayu Liu6c002b62022-05-07 00:40:03 +080057
58 task<Exec>("compileThrift") {
dependabot[bot]5501e8f2025-09-05 16:37:40 -040059 val thriftBin =
60 if (hasProperty("thrift.compiler")) {
61 file(property("thrift.compiler")!!)
62 } else {
63 project.rootDir.resolve("../../compiler/cpp/thrift")
64 }
Jiayu Liu6c002b62022-05-07 00:40:03 +080065 val outputDir = layout.buildDirectory.dir("generated-sources")
dependabot[bot]5501e8f2025-09-05 16:37:40 -040066 doFirst { mkdir(outputDir) }
67 commandLine =
68 listOf(
69 thriftBin.absolutePath,
70 "-gen",
71 "kotlin",
72 "-out",
73 outputDir.get().toString(),
74 layout.projectDirectory
75 .file("src/test/resources/AnnotationTest.thrift")
76 .asFile
77 .absolutePath,
78 )
Jiayu Liu6c002b62022-05-07 00:40:03 +080079 group = LifecycleBasePlugin.BUILD_GROUP
80 }
81
dependabot[bot]5501e8f2025-09-05 16:37:40 -040082 compileKotlin { dependsOn("compileThrift") }
Jiayu Liu6c002b62022-05-07 00:40:03 +080083}
84
dependabot[bot]5501e8f2025-09-05 16:37:40 -040085sourceSets["main"].java { srcDir(layout.buildDirectory.dir("generated-sources")) }