11import java.nio.file.Files
22
3+ import java.nio.charset.Charset
4+
35import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask
46
57plugins {
@@ -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+
2975graalvmNative {
3076 toolchainDetection = System .getenv(" GRAALVM_HOME" ) == null
3177
0 commit comments