When the classpath for a Gradle JavaExec
or Test
task is long, Windows command executions
fail due to Windows path length limitations. The error usually seen in this case is
CreateProcess error=206, The filename or extension is too long
.
This plugin uses the capability of JDK9+ to pass the classpath to the JVM in an "argument file" instead (see java Command-Line Argument Files, thus avoiding the OS limitation.
In addition, this avoids modifying classloading or any other runtime behavior, which is not the case with other solutions such as ones that modify the classpath in the manifest. See:
This plugin takes inspiration from those plugins, but operates in a completely different way.
See this answer to How to set a long Java classpath in Windows? at StackOverflow for more details about this solution.
See this upstream Gradle issue about potentially providing a solution to this problem in Gradle core: gradle/gradle#1989. Hopefully an upstream solution to this will eliminate the need for this plugin.
-
Gradle 8.8+ (may work on earlier versions, but untested)
-
Java 8+.
⚠ Works only if configuration caching is disabled ⚠
Simply add:
plugins {
id 'com.redock.classpathtofile' version '0.1.0'
}
to your build.
For more details, follow the steps described at the Gradle Plugin Portal page.