-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
94 lines (85 loc) · 2.85 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
import com.github.hmiyado.BuildConfigTemplate
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
application
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.ktlint)
alias(libs.plugins.openApi)
}
group = "kottage"
version = "v1"
val generatedSourcePath = buildDir.resolve(File("generated/src/main/kotlin"))
tasks.register("generateBuildConfig") {
outputs.dir(generatedSourcePath)
doLast {
val template = BuildConfigTemplate.from(version.toString())
val file = File("${buildDir.path}/generated/version.txt")
file.appendText(template.version)
template.writeKotlinFileTo(generatedSourcePath)
}
}
application {
if (System.getProperties().getProperty("cli") != null) {
mainClass.set("com.github.hmiyado.kottage.cli.CliEntrypoint")
} else {
mainClass.set("io.ktor.server.netty.EngineMain")
}
}
// https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin
// https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/kotlin-server.md
openApiGenerate {
generatorName.set("kotlin-server")
inputSpec.set("$rootDir/src/main/resources/api-spec/root.json")
outputDir.set("$buildDir/generated")
templateDir.set("$rootDir/src/main/resources/template")
ignoreFileOverride.set("$rootDir/.openapi-generator-ignore")
val rootPackage = "com.github.hmiyado.kottage.openapi"
packageName.set(rootPackage)
library.set("ktor")
typeMappings.set(
mutableMapOf(
"DateTime" to "java.time.ZonedDateTime",
),
)
configOptions.put("enumPropertyNaming", "PascalCase")
verbose.set(false)
}
sourceSets {
main {
java.srcDir(generatedSourcePath)
}
}
repositories {
mavenCentral()
}
val generateBuildConfig by tasks.getting(Task::class)
val openApiGenerate by tasks.getting(Task::class)
val compileKotlin by tasks.getting(KotlinCompile::class) {
kotlinOptions {
jvmTarget = libs.versions.kotlinJvmTarget.get()
}
dependsOn(generateBuildConfig, openApiGenerate)
}
val compileTestKotlin = tasks.getByName("compileTestKotlin") {
if (this is KotlinCompile) {
kotlinOptions {
jvmTarget = libs.versions.kotlinJvmTarget.get()
}
}
dependsOn(generateBuildConfig, openApiGenerate)
}
val test by tasks.getting(Test::class) {
useJUnitPlatform()
jvmArgs = listOf("-Dio.ktor.development=false")
testLogging {
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
events = setOf(TestLogEvent.SKIPPED, TestLogEvent.PASSED, TestLogEvent.FAILED)
}
}
dependencies {
implementation(libs.bundles.kottage)
testImplementation(libs.bundles.testKottage)
}