forked from serpro69/kotlin-faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
141 lines (124 loc) · 3.88 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import kotlinx.validation.KotlinApiBuildTask
import kotlinx.validation.KotlinApiCompareTask
plugins {
application
kotlin("jvm")
id("org.graalvm.buildtools.native") version "0.10.1"
id("com.github.johnrengelman.shadow")
}
val mainFunction = "io.github.serpro69.kfaker.app.KFakerKt"
val mainAppClass = "io.github.serpro69.kfaker.app.KFaker"
val fakers = listOf(
"books",
"commerce",
"creatures",
"databases",
"edu",
"games",
"humor",
"japmedia",
"lorem",
"misc",
"movies",
"music",
"sports",
"tech",
"travel",
"tvshows",
)
dependencies {
implementation(project(path = ":core", configuration = "shadow"))
fakers.forEach { implementation(project(path = ":faker:$it", configuration = "shadow")) }
implementation("info.picocli:picocli:4.7.5")
}
// Test tasks must run after we've built the dependencies
tasks.withType<Test> {
dependsOn(":core:shadowJar")
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
}
application {
// mainClassName = mainFunction
mainClass.set(mainFunction)
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
vendor.set(JvmVendorSpec.matching("Temurin"))
}
}
val shadowJar by tasks.getting(ShadowJar::class) {
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name },
"Main-Class" to mainFunction
)
)
}
archiveClassifier.set("fat")
from(sourceSets.main.get().output)
// from(project.configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
from(project.configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) })
with(tasks.jar.get() as CopySpec)
dependsOn(project.configurations.runtimeClasspath)
// since we're adding :core and :faker:* as implementation dependencies
// we also need to make sure ShadowJar task depend on core having been built
dependsOn(":core:shadowJar")
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
dependsOn(tasks.test)
}
// dunno why, but gradle is complaining that 'startScripts' may run before dependencies have been built
tasks.startScripts {
dependsOn(":core:shadowJar")
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
}
graalvmNative {
testSupport = false
toolchainDetection = true
binaries {
named("main") {
imageName = "faker-bot_${project.version}"
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
vendor.set(JvmVendorSpec.GRAAL_VM)
}
mainClass.set(mainFunction)
}
}
}
//graalvmNative {
// graalVersion("21.2.0")
// javaVersion("8")
// mainClass(mainFunction)
// outputName("faker-bot_${project.version}")
// option("--no-fallback")
// option("--no-server")
// option("--report-unsupported-elements-at-runtime")
//}
tasks {
compileKotlin {
// Set version for --version options
doFirst("Set app version") {
val command = "find . -type f -name 'KFaker.kt' -exec sed -i 's/{FAKER_VER}/${project.version}/g' {} +;"
exec {
commandLine("sh", "-c", command)
}
}
// Restore the file so it's not accidentally committed
doLast {
exec {
commandLine("sh", "-c", "git checkout *KFaker.kt")
}
}
dependsOn(":core:assemble")
}
nativeCompile {
dependsOn(shadowJar)
}
generateResourcesConfigFile {
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
}
}