blob: 16d745bac82bb7667aebf024c432339968d37ef5 [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
27repositories {
28 mavenCentral()
29}
30
31dependencies {
32 implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
33 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
dependabot[bot]bf570822024-10-01 03:44:07 -040034 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.9.0")
Jiayu Liu6c002b62022-05-07 00:40:03 +080035 implementation("org.apache.thrift:libthrift:INCLUDED")
36 testImplementation(kotlin("test"))
37}
38
Jiayu Liuab83ffc2022-05-10 01:56:30 +080039kotlin {
40 jvmToolchain {
thomasbruggink5d0205d2024-11-05 15:33:18 +090041 languageVersion.set(JavaLanguageVersion.of(17))
Jiayu Liuab83ffc2022-05-10 01:56:30 +080042 }
43}
44
thomasbruggink5d0205d2024-11-05 15:33:18 +090045java {
46 sourceCompatibility = JavaVersion.VERSION_1_8
47 targetCompatibility = JavaVersion.VERSION_1_8
48}
49
50tasks.withType<KotlinCompile> {
Christopher Tubbs8922f172024-09-17 20:42:24 -040051 compilerOptions {
thomasbruggink5d0205d2024-11-05 15:33:18 +090052 jvmTarget = JvmTarget.JVM_1_8
53 freeCompilerArgs = listOf("-Xjdk-release=1.8")
Christopher Tubbs8922f172024-09-17 20:42:24 -040054 }
Fokko Driesprong0b14a1b2023-04-14 11:06:15 +020055}
56
Jiayu Liu6c002b62022-05-07 00:40:03 +080057tasks {
Jiayu Liu5b158382022-05-12 00:20:37 +080058 if (JavaVersion.current().isJava11Compatible) {
59 ktfmt {
60 kotlinLangStyle()
61 }
Jiayu Liu6c002b62022-05-07 00:40:03 +080062 }
63
64 test {
65 useJUnitPlatform()
66 }
67
68 task<Exec>("compileThrift") {
69 val thriftBin = if (hasProperty("thrift.compiler")) {
Jiayu Liua4e11362023-07-05 08:32:55 +000070 file(property("thrift.compiler")!!)
Jiayu Liu6c002b62022-05-07 00:40:03 +080071 } 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
94sourceSets["main"].java {
95 srcDir(layout.buildDirectory.dir("generated-sources"))
96}