This is an automated email from the ASF dual-hosted git repository.

jamesfredley pushed a commit to branch JavaExec-argsFile
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 67a7f162feb614b81379eb5f83f3403aeb50ffa6
Author: James Fredley <[email protected]>
AuthorDate: Mon Sep 22 16:37:28 2025 -0400

    Add argfile support to JavaExec tasks to fix long classpaths
    
    Introduces an argfile approach for JavaExec tasks to mitigate command line 
length issues, particularly when launching Java processes with long classpaths 
(e.g., assetCompile). Adds a ClasspathArgfileProvider to supply the classpath 
via an argument file, improving reliability on systems with command line length 
limits.
---
 .../gradle/plugin/core/GrailsGradlePlugin.groovy   | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git 
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
 
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
index a640b93977..a60e69f9d4 100644
--- 
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
+++ 
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
@@ -54,6 +54,7 @@ import org.gradle.api.tasks.compile.GroovyCompile
 import org.gradle.api.tasks.testing.Test
 import org.gradle.language.jvm.tasks.ProcessResources
 import org.gradle.process.JavaForkOptions
+import org.gradle.process.CommandLineArgumentProvider
 import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
 
 import org.springframework.boot.gradle.dsl.SpringBootExtension
@@ -576,6 +577,24 @@ class GrailsGradlePlugin extends GroovyPlugin {
         String grailsEnvSystemProperty = System.getProperty(Environment.KEY)
         
tasks.withType(Test).each(systemPropertyConfigurer.curry(grailsEnvSystemProperty
 ?: Environment.TEST.getName()))
         
tasks.withType(JavaExec).each(systemPropertyConfigurer.curry(grailsEnvSystemProperty
 ?: Environment.DEVELOPMENT.getName()))
+
+        // Mitigate command line length issues when launching Java processes 
(e.g., assetCompile) using argfile approach
+        tasks.withType(JavaExec).configureEach { JavaExec execTask ->
+            execTask.doFirst {
+                try {
+                    String cp = execTask.classpath?.asPath ?: ''
+                    if (cp) {
+                        File argsFile = new 
File(project.layout.buildDirectory.get().asFile, 
"tmp${File.separator}javaexec-args${File.separator}${execTask.name}.args")
+                        argsFile.parentFile.mkdirs()
+                        argsFile.text = "-cp\n\"${cp}\""
+                        execTask.setClasspath(project.files())
+                        execTask.jvmArgumentProviders.add(new 
ClasspathArgfileProvider(argsFile))
+                    }
+                } catch (Throwable ignored) {
+                    // If anything goes wrong, continue without the argsFile
+                }
+            }
+        }
     }
 
     protected void configureConsoleTask(Project project) {
@@ -884,4 +903,14 @@ class GrailsGradlePlugin extends GroovyPlugin {
     private static final class OnlyOneGrailsPlugin {
         String pluginClassname
     }
+
+    @CompileStatic
+    static final class ClasspathArgfileProvider implements 
CommandLineArgumentProvider {
+        final File argsFile
+        ClasspathArgfileProvider(File file) { this.argsFile = file }
+        @Override
+        Iterable<String> asArguments() {
+            return ["@${argsFile.absolutePath}".toString()]
+        }
+    }
 }

Reply via email to