-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
175 lines (150 loc) · 5.75 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import groovy.json.JsonSlurper
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import java.util.jar.JarFile
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.yaml:snakeyaml:2.0")
}
}
plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.jlleitschuh.gradle.ktlint") version "11.3.2"
id("io.ktor.plugin") version "2.3.0"
}
val group: String by project
val mcApiVersion: String by project
val ktorVersion: String by project
@Suppress("UNCHECKED_CAST")
val version = (JsonSlurper().parseText(File("package.json").readText()) as Map<String, String>)["version"] as String
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
implementation(kotlin("stdlib"))
// implementation("io.ktor:ktor-server-core:$ktorVersion")
// implementation("io.ktor:ktor-server-netty:$ktorVersion")
// implementation("io.ktor:ktor-server-websockets:$ktorVersion")
// implementation("io.ktor:ktor-client-core:$ktorVersion")
// implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
// implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("org.java-websocket:Java-WebSocket:1.5.3")
implementation("com.google.code.gson:gson:2.10.1")
// implementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+")
}
val relocatingApi: Configuration by configurations.creating
val relocatingImplementation: Configuration by configurations.creating
configurations.api { extendsFrom(relocatingApi) }
configurations.implementation { extendsFrom(relocatingImplementation) }
dependencies {
// relocatingApi("io.ktor:ktor-server-core:$ktorVersion")
// relocatingApi("io.ktor:ktor-client-okhttp:$ktorVersion")
// relocatingApi(kotlin("stdlib"))
relocatingApi("org.java-websocket:Java-WebSocket:1.5.3")
relocatingApi("com.google.code.gson:gson:2.10.1")
// relocatingApi("com.fasterxml.jackson.core:jackson-databind:2.14.2")
}
tasks {
wrapper {
gradleVersion = "8.1.1"
distributionType = Wrapper.DistributionType.ALL
}
processResources {
val placeholders = mapOf(
"version" to version,
"apiVersion" to mcApiVersion,
"kotlinVersion" to project.properties["kotlinVersion"],
)
filesMatching("plugin.yml") {
expand(placeholders)
}
// create an "offline" copy/variant of the plugin.yml with `libraries` omitted
doLast {
val resourcesDir = sourceSets.main.get().output.resourcesDir
val yamlDumpOptions =
// make it pretty for the people
DumperOptions().also {
it.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
it.isPrettyFlow = true
}
val yaml = Yaml(yamlDumpOptions)
val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream())
yaml.dump(pluginYml.filterKeys { it != "libraries" }, file("$resourcesDir/offline-plugin.yml").writer())
}
}
jar {
exclude("offline-plugin.yml")
}
val configureRelocation by creating {
val relocatingConfigurations = listOf(relocatingApi, relocatingImplementation)
val packages = buildSet {
relocatingConfigurations.forEach { config ->
config.files.forEach { jar ->
JarFile(jar).use { jarFile ->
jarFile.entries().asSequence().forEach { entry ->
if (entry.name.endsWith(".class") && entry.name != "module-info.class") {
val lastSlash = entry.name.lastIndexOf('/')
val pkg = entry.name.substring(0..lastSlash).replace('/', '.')
add(pkg)
}
}
}
}
}
}
val prefix = "${project.group}.libraries"
shadowJar {
packages.forEach {
relocate(it, "$prefix.$it")
}
}
}
project.setProperty("mainClassName", "fyi.fyw.mc.pluginnonebot.PluginNonebot")
// offline jar should be ready to go with all dependencies
shadowJar {
minimize()
exclude("plugin.yml")
dependencies {
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
}
rename("offline-plugin.yml", "plugin.yml")
}
build {
dependsOn(shadowJar).dependsOn(configureRelocation)
doLast {
file("build/libs").listFiles()?.forEach {
if (it.name.endsWith("all.jar")) {
it.renameTo(file("build/libs/${project.name}-$version-all.jar"))
}
}
}
}
register("devDebug") {
dependsOn(ktlintFormat).dependsOn(build)
doLast {
copy {
from("build/libs/${project.name}-$version-all.jar")
rename("${project.name}-$version-all.jar", "${project.name}.jar")
into("../../Bukkit-plugin/server/plugins/")
}
}
}
ktlint {
version.set("0.48.2")
verbose.set(true)
outputToConsole.set(true)
enableExperimentalRules.set(true)
}
}