forked from yyuueexxiinngg/onebot-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
144 lines (123 loc) · 4.63 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
plugins {
kotlin("jvm") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
java
id("com.github.johnrengelman.shadow") version "6.0.0"
id("com.github.gmazzo.buildconfig") version "2.0.2"
}
val projectVersion = "0.2.3"
version = projectVersion
group = "yyuueexxiinngg"
repositories {
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
gradlePluginPortal()
jcenter()
mavenCentral()
}
val miraiCoreVersion = "1.2.0"
val miraiConsoleVersion = "0.5.2"
val ktorVersion = "1.4.0"
val kotlinVersion = "1.4.0"
val kotlinSerializationVersion = "1.0.0-RC"
fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
fun String.runCommand(workingDir: File): String? {
return try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
proc.waitFor(60, TimeUnit.MINUTES)
proc.inputStream.bufferedReader().readText().trim()
} catch (e: java.io.IOException) {
e.printStackTrace()
null
}
}
dependencies {
compileOnly(kotlin("stdlib-jdk8"))
compileOnly("net.mamoe:mirai-core:$miraiCoreVersion")
compileOnly("net.mamoe:mirai-console:$miraiConsoleVersion")
compileOnly(kotlin("serialization", kotlinVersion))
implementation(kotlinx("serialization-cbor", kotlinSerializationVersion))
implementation("ch.qos.logback:logback-classic:1.2.3")
api(ktor("server-cio"))
api(ktor("client-okhttp"))
api(ktor("websockets"))
api(ktor("client-websockets"))
api(kotlin("reflect", kotlinVersion))
testImplementation(kotlin("stdlib-jdk8"))
testImplementation("net.mamoe:mirai-core:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-core-qqandroid:$miraiCoreVersion")
testImplementation("net.mamoe:mirai-console:$miraiConsoleVersion")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
val injectVersionToPluginDesc by register("injectVersionToPluginDesc") {
group = "cqhttp-mirai"
doLast {
val pluginDescFile = File(projectDir, "src/main/resources/plugin.yml")
val lines = pluginDescFile.readLines().toMutableList()
lines[2] = "version: \"$projectVersion\""
pluginDescFile.writeText(lines.joinToString(separator = "\n"))
}
}
buildConfig {
val commitHash = "git rev-parse --short HEAD".runCommand(projectDir)
buildConfigField("String", "VERSION", "\"$projectVersion\"")
if (commitHash != null) { buildConfigField("String", "COMMIT_HASH", "\"$commitHash\"") }
}
shadowJar {
dependsOn(generateBuildConfig)
dependsOn(injectVersionToPluginDesc)
}
val runMiraiConsole by creating(JavaExec::class.java) {
group = "mirai"
main = "mirai.RunMirai"
dependsOn(shadowJar)
dependsOn(testClasses)
val testConsoleDir = "test"
doFirst {
fun removeOldVersions() {
File("$testConsoleDir/plugins/").walk()
.filter { it.name.matches(Regex("""${project.name}-.*-all.jar""")) }
.forEach {
it.delete()
println("deleting old files: ${it.name}")
}
}
fun copyBuildOutput() {
File("build/libs/").walk()
.filter { it.name.contains("-all") }
.maxBy { it.lastModified() }
?.let {
println("Coping ${it.name}")
it.inputStream()
.transferTo(File("$testConsoleDir/plugins/${it.name}").apply { createNewFile() }
.outputStream())
println("Copied ${it.name}")
}
}
workingDir = File(testConsoleDir)
workingDir.mkdir()
File(workingDir, "plugins").mkdir()
removeOldVersions()
copyBuildOutput()
classpath = sourceSets["test"].runtimeClasspath
standardInput = System.`in`
args(miraiCoreVersion, miraiConsoleVersion)
}
}
}