While working on Java gradle project sometimes we might get the following error in Windows system:
Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
This is due to when classpath for a Gradle JavaExec or Test task is long, Windows command executions give an error because of the limitation to command line length greater than 32K
With a number of classpath dependencies in a large project, typically JavaExec Gradle task fails with error "The filename or extension is too long" and this would be a stopping error. To solve this issue, we can use the following gradle plugin. Use the plugin inside build.gradle file
apply plugin: "com.virgo47.ClasspathJar"
Or we can use inside build.gradle file under buildscript {} >> dependencies {} section as below:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.virgo47.gradle:ClasspathJar:1.0.0"
}
}
For Kotlin project, use it inside build.gradle.kts file as below:
apply(plugin = "com.virgo47.ClasspathJar")
Or we can use it in the build.gradle.kts kotlin file under buildscript {} >> dependencies {}
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.com.virgo47.gradle:ClasspathJar:1.0.0")
}
}
ClasspathJar plugin creates a classpath jar for jar files in the classpath and sets the classpath with classpath jar. This includes JavaExec, Test and other similar tasks.
Build the application and run it.
Reference: ClasspathJar