blob: c68f393ac26ea1d401a5b90785ab95103ebd1baa [file] [log] [blame]
Jiayu Liu49b2d6b2022-04-06 16:49:09 +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 {
Jiayu Liu6c002b62022-05-07 00:40:03 +080021 kotlin("jvm")
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080022 java
23 application
Jiayu Liu5b158382022-05-12 00:20:37 +080024 id("com.ncorti.ktfmt.gradle")
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080025}
26
27repositories {
28 mavenCentral()
29}
30
Jiayu Liueb62fa82022-05-08 13:01:41 +080031val slf4jVersion: String by project
32val httpclientVersion: String by project
33val httpcoreVersion: String by project
34val logbackVersion: String by project
35val kotlinxCoroutinesJdk8Version: String by project
Jiayu Liu5fdfd0c2022-05-09 10:52:26 +080036val cliktVersion: String by project
Jiayu Liueb62fa82022-05-08 13:01:41 +080037
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080038dependencies {
39 implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
40 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
Jiayu Liu5fdfd0c2022-05-09 10:52:26 +080041 // clikt is used to drive command line parsing and validation
42 implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
Jiayu Liueb62fa82022-05-08 13:01:41 +080043 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlinxCoroutinesJdk8Version")
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080044 implementation("org.apache.thrift:libthrift:INCLUDED")
Jiayu Liueb62fa82022-05-08 13:01:41 +080045 implementation("org.slf4j:slf4j-api:$slf4jVersion")
46 implementation("org.apache.httpcomponents:httpclient:$httpclientVersion")
47 implementation("org.apache.httpcomponents:httpcore:$httpcoreVersion")
Jiayu Liueb62fa82022-05-08 13:01:41 +080048 implementation("ch.qos.logback:logback-classic:$logbackVersion")
49 testImplementation("org.jetbrains.kotlin:kotlin-test")
50 testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080051}
52
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080053tasks {
54 application {
55 applicationName = "TestClient"
56 mainClass.set("org.apache.thrift.test.TestClientKt")
57 }
58
Jiayu Liu5b158382022-05-12 00:20:37 +080059 if (JavaVersion.current().isJava11Compatible) {
60 ktfmt {
61 kotlinLangStyle()
62 }
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080063 }
64
65 task<Exec>("compileThrift") {
66 val thriftBin = if (hasProperty("thrift.compiler")) {
Jiayu Liua4e11362023-07-05 08:32:55 +000067 file(property("thrift.compiler")!!)
Jiayu Liu49b2d6b2022-04-06 16:49:09 +080068 } else {
69 project.rootDir.resolve("../../compiler/cpp/thrift")
70 }
71 val outputDir = layout.buildDirectory.dir("generated-sources")
72 doFirst {
73 mkdir(outputDir)
74 }
75 commandLine = listOf(
76 thriftBin.absolutePath,
77 "-gen",
78 "kotlin",
79 "-out",
80 outputDir.get().toString(),
81 project.rootDir.resolve("../../test/ThriftTest.thrift").absolutePath
82 )
83 group = LifecycleBasePlugin.BUILD_GROUP
84 }
85
86 compileKotlin {
87 dependsOn("compileThrift")
88 }
89}
90
91sourceSets["main"].java {
92 srcDir(layout.buildDirectory.dir("generated-sources"))
93}