1
+ import java.io.FileOutputStream
2
+ import java.util.jar.*
3
+
1
4
plugins {
2
5
kotlin(" jvm" ) version " 2.0.21"
3
6
kotlin(" plugin.serialization" ) version " 2.0.21"
4
7
id(" com.gradleup.shadow" ) version " 8.3.5"
5
8
}
6
9
7
- group = " io.github.sploonmc.builder "
8
- version = " 1 .0.0-SNAPSHOT "
10
+ group = " io.github.sploonmc.bundler "
11
+ version = " 0 .0.0"
9
12
10
13
dependencies {
11
14
implementation(" com.github.codemonstur:simplexml:3.2.0" )
@@ -14,16 +17,63 @@ dependencies {
14
17
implementation(" org.ow2.asm:asm:9.7.1" )
15
18
}
16
19
17
- tasks.shadowJar {
18
- archiveClassifier = " "
19
- }
20
+ tasks {
21
+ shadowJar {
22
+ archiveClassifier = " "
23
+ version = " "
24
+ minimize()
25
+ }
20
26
21
- tasks.build {
22
- dependsOn(tasks.shadowJar)
23
- }
27
+ build {
28
+ dependsOn(shadowJar)
29
+ }
30
+
31
+ jar {
32
+ manifest {
33
+ attributes[" Main-Class" ] = " io.github.sploonmc.bundler.MainKt"
34
+ }
35
+ }
36
+
37
+ abstract class VersionTask : DefaultTask () {
38
+ @get:Input
39
+ abstract val version: Property <String >
40
+
41
+ init {
42
+ group = " bundler-versioning"
43
+ description = " Creates a jar for a specific Minecraft version: $version "
44
+ }
24
45
25
- tasks.jar {
26
- manifest {
27
- attributes[" Main-Class" ] = " io.github.sploonmc.builder.MainKt"
46
+ @TaskAction
47
+ fun createVersionedJar () {
48
+ val version = version.get()
49
+
50
+ val jarFile = project.layout.buildDirectory.file(" libs/${project.name} .jar" ).get().asFile
51
+ val outputFile = jarFile.parentFile.resolve(" ${project.name} -$version .jar" )
52
+ outputFile.delete()
53
+
54
+ logger.lifecycle(" Creating versioned jar: ${outputFile.absolutePath} " )
55
+
56
+ JarFile (jarFile).use { jar ->
57
+ JarOutputStream (FileOutputStream (outputFile)).use { output ->
58
+ jar.entries().asSequence().forEach { entry ->
59
+ output.putNextEntry(JarEntry (entry.name))
60
+ jar.getInputStream(entry).use { it.copyTo(output) }
61
+ }
62
+
63
+ output.putNextEntry(JarEntry (" META-INF/sploon.version" ))
64
+ version.byteInputStream().use { it.copyTo(output) }
65
+ }
66
+ }
67
+
68
+ logger.lifecycle(" Versioned jar created at: ${outputFile.absolutePath} " )
69
+ }
28
70
}
29
- }
71
+
72
+ fun versionTask (version : String ) = register<VersionTask >(version.replace(" ." , " _" )) {
73
+ dependsOn(shadowJar)
74
+ this .version = version
75
+ }
76
+
77
+ versionTask(" 1.21.3" )
78
+ versionTask(" 1.21.1" )
79
+ }
0 commit comments