Skip to content

Commit 29527e0

Browse files
committed
feat(cli): Use a "pathing" JAR to shortend the classpath argument
1 parent 3ca54ac commit 29527e0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

cli/build.gradle.kts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,50 @@ dependencies {
2626
implementation(libs.kotlinReflect)
2727
}
2828

29+
val jar by tasks.getting(Jar::class)
30+
31+
val pathingJar by tasks.registering(Jar::class) {
32+
archiveClassifier = "pathing"
33+
34+
manifest {
35+
// Work around the command line length limit on Windows when passing the classpath to Java, see
36+
// https://github.com/gradle/gradle/issues/1989.
37+
attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(" ") { it.name }
38+
}
39+
}
40+
41+
distributions {
42+
main {
43+
contents {
44+
from(pathingJar) {
45+
into("lib")
46+
}
47+
}
48+
}
49+
}
50+
51+
tasks.named<CreateStartScripts>("startScripts") {
52+
classpath = jar.outputs.files + pathingJar.get().outputs.files
53+
54+
doLast {
55+
// Append the plugin directory to the Windows classpath.
56+
val windowsScriptText = windowsScript.readText(Charset.defaultCharset())
57+
windowsScript.writeText(
58+
windowsScriptText.replace(
59+
Regex("(set CLASSPATH=%APP_HOME%\\\\lib\\\\.*)"), "$1;%APP_HOME%\\\\plugin\\\\*"
60+
)
61+
)
62+
63+
// Append the plugin directory to the Unix classpath.
64+
val unixScriptText = unixScript.readText(Charset.defaultCharset())
65+
unixScript.writeText(
66+
unixScriptText.replace(
67+
Regex("(CLASSPATH=\\\$APP_HOME/lib/.*)"), "$1:\\\$APP_HOME/plugin/*"
68+
)
69+
)
70+
}
71+
}
72+
2973
graalvmNative {
3074
toolchainDetection = System.getenv("GRAALVM_HOME") == null
3175

0 commit comments

Comments
 (0)