Skip to content

Commit 3708242

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

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cli/build.gradle.kts

Lines changed: 42 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,46 @@ 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(Regex("(set CLASSPATH=%APP_HOME%\\\\lib\\\\.*)"), "$1;%APP_HOME%\\\\plugin\\\\*")
61+
)
62+
63+
// Append the plugin directory to the Unix classpath.
64+
val unixScriptText = unixScript.readText(Charset.defaultCharset())
65+
unixScript.writeText(
66+
unixScriptText.replace(Regex("(CLASSPATH=\\\$APP_HOME/lib/.*)"), "$1:\\\$APP_HOME/plugin/*")
67+
)
68+
}
69+
}
70+
2971
graalvmNative {
3072
toolchainDetection = System.getenv("GRAALVM_HOME") == null
3173

0 commit comments

Comments
 (0)