-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
102 lines (84 loc) · 2.94 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
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
import org.apache.tools.zip.ZipEntry
import org.apache.tools.zip.ZipOutputStream
import org.codehaus.plexus.util.IOUtil
import java.io.ByteArrayOutputStream
import java.util.jar.JarFile.MANIFEST_NAME
import java.util.jar.Manifest as JManifest
plugins {
application
id("com.github.johnrengelman.shadow") version "8.1.1"
}
version = "0.1.0"
val include: Configuration by configurations.creating {
isTransitive = false
description = "Shaded dependencies"
val implementation by configurations
implementation.extendsFrom(this)
}
dependencies {
include(project(":jsandbox-api"))
include(project(":"))
include("info.picocli:picocli:4.7.5")
include("ch.qos.logback:logback-classic:1.4.11")
}
application {
mainClass.set("enterprises.stardust.jsandbox.cli.Main")
}
tasks {
withType<CreateStartScripts> {
applicationName = "jsandbox"
}
jar {
val mainClass = application.mainClass.get()
manifest.attributes["Main-Class"] = mainClass
val pkg = mainClass.substringBeforeLast('.')
.replace('.', '/')
manifest.attributes(
"$pkg/",
"Implementation-Title" to "jsandbox-cli",
"Implementation-Version" to project.version.toString(),
"Implementation-Vendor" to "Stardust Enterprises"
)
}
shadowJar {
manifest.inheritFrom(jar.get().manifest)
configurations = listOf(include)
transformers = listOf(ManifestMergeTransformer())
duplicatesStrategy = DuplicatesStrategy.WARN
}
build.get().dependsOn(shadowJar)
}
class ManifestMergeTransformer : Transformer {
private var manifest: JManifest? = null
override fun getName(): String =
"ManifestMergeTransformer"
override fun canTransformResource(element: FileTreeElement?): Boolean =
MANIFEST_NAME.equals(element?.relativePath?.pathString, ignoreCase = true)
override fun transform(context: TransformerContext) {
if (manifest == null) {
manifest = JManifest(context.`is`)
} else {
val toMerge = JManifest(context.`is`)
for ((key, value) in toMerge.entries.entries) {
manifest!!.entries[key] = value
}
}
@Suppress("DEPRECATION")
IOUtil.close(context.`is`)
}
override fun hasTransformedResource(): Boolean =
true
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
val entry = ZipEntry(MANIFEST_NAME)
entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time)
os.putNextEntry(entry)
manifest?.let {
os.write(ByteArrayOutputStream().use { bos ->
it.write(bos)
bos.toByteArray()
})
}
}
}