blob: 3f8b653ca5ac9ad1d1beef65a3bac072aacfbc0e [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 */
19
20plugins {
21 kotlin("jvm")
22 id("com.ncorti.ktfmt.gradle")
23}
24
25repositories {
26 mavenCentral()
27}
28
29dependencies {
30 implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
31 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
dependabot[bot]5c580072024-06-01 06:57:34 +000032 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.8.1")
Jiayu Liu6c002b62022-05-07 00:40:03 +080033 implementation("org.apache.thrift:libthrift:INCLUDED")
34 testImplementation(kotlin("test"))
35}
36
Jiayu Liuab83ffc2022-05-10 01:56:30 +080037kotlin {
38 jvmToolchain {
Fokko Driesprong0b14a1b2023-04-14 11:06:15 +020039 (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(8))
Jiayu Liuab83ffc2022-05-10 01:56:30 +080040 }
41}
42
Jiayu Liua4e11362023-07-05 08:32:55 +000043tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
Christopher Tubbs8922f172024-09-17 20:42:24 -040044 compilerOptions {
45 jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
46 }
Fokko Driesprong0b14a1b2023-04-14 11:06:15 +020047}
48
Jiayu Liu6c002b62022-05-07 00:40:03 +080049tasks {
Jiayu Liu5b158382022-05-12 00:20:37 +080050 if (JavaVersion.current().isJava11Compatible) {
51 ktfmt {
52 kotlinLangStyle()
53 }
Jiayu Liu6c002b62022-05-07 00:40:03 +080054 }
55
56 test {
57 useJUnitPlatform()
58 }
59
60 task<Exec>("compileThrift") {
61 val thriftBin = if (hasProperty("thrift.compiler")) {
Jiayu Liua4e11362023-07-05 08:32:55 +000062 file(property("thrift.compiler")!!)
Jiayu Liu6c002b62022-05-07 00:40:03 +080063 } else {
64 project.rootDir.resolve("../../compiler/cpp/thrift")
65 }
66 val outputDir = layout.buildDirectory.dir("generated-sources")
67 doFirst {
68 mkdir(outputDir)
69 }
70 commandLine = listOf(
71 thriftBin.absolutePath,
72 "-gen",
73 "kotlin",
74 "-out",
75 outputDir.get().toString(),
76 layout.projectDirectory.file("src/test/resources/AnnotationTest.thrift").asFile.absolutePath
77 )
78 group = LifecycleBasePlugin.BUILD_GROUP
79 }
80
81 compileKotlin {
82 dependsOn("compileThrift")
83 }
84}
85
86sourceSets["main"].java {
87 srcDir(layout.buildDirectory.dir("generated-sources"))
88}