-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
115 lines (99 loc) · 3.12 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import com.diffplug.gradle.spotless.SpotlessExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.3.5"
id("io.spring.dependency-management") version "1.1.6"
val kotlinVersion = "2.0.21"
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
id("org.openapi.generator") version "7.9.0"
id("com.diffplug.spotless") version "6.25.0"
}
java.sourceCompatibility = JavaVersion.VERSION_21
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
dependsOn("openApiGenerate")
compilerOptions {
jvmTarget = JvmTarget.JVM_21
}
}
val apiDirectoryPath = "$projectDir/src/main/resources/api"
val openApiGenerateOutputDir =
"${layout.buildDirectory.get()}/generated/openapi"
openApiGenerate {
generatorName = "kotlin-spring"
inputSpec = "$apiDirectoryPath/spec.yml"
outputDir = openApiGenerateOutputDir
apiPackage = "com.yonatankarp.openapi"
modelPackage = "com.yonatankarp.openapi.models"
configOptions =
mapOf(
"dateLibrary" to "java8",
"interfaceOnly" to "true",
"implicitHeaders" to "true",
"hideGenerationTimestamp" to "true",
"useTags" to "true",
"documentationProvider" to "none",
"useSpringBoot3" to "true",
)
}
tasks {
register("cleanGeneratedCodeTask") {
description = "Removes generated Open API code"
doLast {
File(openApiGenerateOutputDir).deleteRecursively()
}
}
clean { dependsOn("cleanGeneratedCodeTask") }
}
sourceSets.main {
kotlin {
srcDir("$openApiGenerateOutputDir/src/main/kotlin")
}
}
configure<SpotlessExtension> {
kotlin {
// see https://github.com/shyiko/ktlint#standard-rules
ktlint()
target(
project.fileTree(project.rootDir) {
include("**/*.kt")
exclude("**/generated/**")
},
)
}
kotlinGradle {
trimTrailingWhitespace()
ktlint()
target(
project.fileTree(project.rootDir) {
include("**/*.kts")
exclude("**/generated/**")
},
)
}
}
val tasksDependencies =
mapOf(
"spotlessKotlin" to listOf("spotlessKotlinGradle", "compileTestKotlin", "test"),
"spotlessKotlinGradle" to listOf("processResources", "compileKotlin", "compileTestKotlin", "test"),
)
tasksDependencies.forEach { (task, dependsOn) ->
dependsOn.forEach {
tasks.findByName(task)!!.dependsOn(it)
}
}