Skip to content

Commit 2f7bf47

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

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

cli/build.gradle.kts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import java.nio.file.Files
22

3+
import java.nio.charset.Charset
4+
35
import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask
46

57
plugins {
@@ -26,6 +28,50 @@ dependencies {
2628
implementation(libs.kotlinReflect)
2729
}
2830

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

0 commit comments

Comments
 (0)