This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
161 lines (141 loc) · 4.82 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.io.ByteArrayOutputStream
import java.io.FileInputStream
import java.time.ZoneId
import java.util.Properties
import java.time.format.DateTimeFormatter
import java.time.ZonedDateTime
val versionPropertiesFile = "${projectDir}/project.properties"
val dependenciesPropertiesFile = "${projectDir}/versions.properties"
fun String.runCommand(currentWorkingDir: File = file("./")): String {
val byteOut = ByteArrayOutputStream()
project.exec {
workingDir = currentWorkingDir
commandLine = [email protected]("\\s".toRegex())
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}
fun getRevision(): String {
return "git rev-parse --short=7 HEAD".runCommand()
}
fun getProperties(file: String, key: String): String {
val fileInputStream = FileInputStream(file)
val props = Properties()
props.load(fileInputStream)
return props.getProperty(key)
}
fun getVersion(): String {
return getProperties(versionPropertiesFile, "version")
}
fun getStage(): String {
return getProperties(versionPropertiesFile, "stage")
}
fun getDependenciesInfo(): String {
val fileInputStream = FileInputStream(dependenciesPropertiesFile)
val props = Properties()
props.load(fileInputStream)
var dependencies = ""
for (key in props.keys) {
val dependency: String = key.toString()
.replace("version.", "")
.replace("plugin.", "")
.replace("..", ".")
val version = props.getProperty(key.toString())
dependencies += "$dependency:$version;"
}
return if (dependencies == "") {
dependencies
} else {
dependencies.substring(0, dependencies.length - 1)
}
}
plugins {
application
kotlin("jvm")
id("com.github.johnrengelman.shadow")
id("de.comahe.i18n4k")
}
group = "tech.ixor"
version = getVersion() + "-" + getStage() + "+" + getRevision()
i18n4k {
sourceCodeLocales = listOf("en", "zh_CN")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "17"
}
}
val projectProps by registering(WriteProperties::class) {
outputFile = file("${projectDir}/src/main/resources/version.properties")
encoding = "UTF-8"
property("version", getVersion())
property("stage", getStage())
property("revision", getRevision())
property("buildDate",
ZonedDateTime
.now(ZoneId.of("UTC"))
.format(DateTimeFormatter.ofPattern("E, MMM dd yyyy"))
)
property("dependencies", getDependenciesInfo())
}
var shadowJarVersion = getVersion()
shadowJar {
if (getStage() == "SNAPSHOT" || getStage() == "alpha" || getStage() == "beta" || getStage() == "rc") {
shadowJarVersion = shadowJarVersion + "-" + getStage()
}
shadowJarVersion = shadowJarVersion + "+" + getRevision()
destinationDirectory.set(file("${projectDir}/build/distributions"))
archiveVersion.set(shadowJarVersion)
archiveClassifier.set("")
}
val copyAllContributorSrc = register<Copy>("copyAllContributorSrc") {
from(layout.projectDirectory.file(".all-contributorsrc"))
into(layout.projectDirectory.dir("src/main/resources"))
}
processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(generateI18n4kFiles)
dependsOn(copyAllContributorSrc)
exclude("conf/config.yaml")
from(projectProps)
}
}
application {
mainClass.set("tech.ixor.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
}
dependencies {
// Dependencies
// i18n
implementation("de.comahe.i18n4k:i18n4k-core-jvm:_")
// JSON Parser
implementation("com.beust:klaxon:_")
// Scheduled Jobs
implementation("dev.inmo:krontab:_")
// Config Loader
implementation("com.sksamuel.hoplite:hoplite-core:_")
implementation("com.sksamuel.hoplite:hoplite-json:_")
implementation("com.sksamuel.hoplite:hoplite-yaml:_")
// Ktor
implementation("io.ktor:ktor-server-core-jvm:_")
implementation("io.ktor:ktor-server-netty-jvm:_")
implementation("io.ktor:ktor-server-html-builder-jvm:_")
implementation("io.ktor:ktor-server-content-negotiation-jvm:_")
implementation(Ktor.server.contentNegotiation)
implementation(Ktor.plugins.serialization.gson)
implementation("io.ktor:ktor-client-core-jvm:_")
implementation("io.ktor:ktor-client-okhttp:_")
implementation("io.ktor:ktor-client-okhttp-jvm:_")
// Logback
implementation("ch.qos.logback:logback-classic:_")
// Test Dependencies
// Ktor
// Kotlin
testImplementation(Kotlin.test.junit)
testImplementation("io.ktor:ktor-server-tests-jvm:_")
}