-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle.kts
91 lines (73 loc) · 2.64 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
import java.io.FileOutputStream
import java.io.IOException
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
plugins{
id("eternalcode.java")
id("com.github.johnrengelman.shadow")
id("xyz.jpenilla.run-paper") version "2.3.0"
}
tasks.create("shadowAll") {
group = "shadow"
val projects = listOf(
project(":chatformatter-core"),
project(":chatformatter-paper-plugin")
)
for (project in projects) {
dependsOn(project.name + ":shadowJar")
}
doLast {
merge("ChatFormatter v${project.version}.jar", projects)
}
}
fun merge(archiveFileName: String, projects: List<Project>) {
val outputFile = File(project.layout.buildDirectory.asFile.get(), "libs/${archiveFileName}")
val outputDir = outputFile.parentFile ?: throw RuntimeException("Could not get output directory")
if (!outputDir.exists() && !outputDir.mkdirs()) {
throw RuntimeException("Could not create output directory")
}
if (outputFile.exists()) {
outputFile.delete()
}
if (!outputFile.createNewFile()) {
throw RuntimeException("Could not find output file to merge")
}
JarOutputStream(FileOutputStream(outputFile)).use { outputJar ->
for (project in projects) {
val shadowJar = project.tasks.shadowJar.get()
for (file in shadowJar.outputs.files.files) {
JarFile(file).use { jarFile ->
for (entry in jarFile.entries()) {
if (entry.isDirectory) {
continue
}
val bytes = jarFile.getInputStream(entry).readBytes()
val newEntry = JarEntry(entry.name)
newEntry.setTime(System.currentTimeMillis())
newEntry.setSize(bytes.size.toLong())
try {
outputJar.putNextEntry(newEntry)
outputJar.write(bytes)
outputJar.closeEntry()
}
catch (exception: IOException) {
if (exception.message?.contains("duplicate entry: ") == true) {
continue
}
exception.printStackTrace()
}
}
}
}
}
}
}
runPaper {
disablePluginJarDetection()
}
tasks.runServer {
minecraftVersion("1.20.4")
dependsOn("shadowAll")
pluginJars = files("/build/libs/ChatFormatter v${project.version}.jar")
}