When classpath for a Gradle JavaExec
or Test
task is long, Windows command executions give
error because of 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, use ClasspathJar plugin.
ClasspathJar
plugin creates a classpath jar for jar files in the classpath
of every JavaForkOptions task and sets the classpath with classpath jar.
This includes JavaExec
, Test
and other similar tasks.
My story started with the problem, followed with a blog post. Then I found a plugin only to discover it had a bug that stays hidden if you don’t use spaces in path.
This plugin is clone of https://github.com/eshepelyuk/gradle-util-plugins which itself is clone of other "gradle-util-plugins".
My version uses toURI()
instead of toURL()
to process classpath items which should fix
file paths with spaces.
Original repo didn’t have Issues tab, so I couldn’t report it easily.
I also wanted to start with Gradle plugins and this one is as good as any other for that
plus I can scratch my own itch.
TODO: I should have added test for this but right now it’s beyond my Gradle skill.
Also it’s not possible to upgrade from Gradle 4.7 to 4.8 and higher, as it breaks half the tests. See: https://discuss.gradle.org/t/plugin-tests-using-project-tasks-test-worked-in-4-7-but-fail-with-4-8/29340?u=virgo47
Follow the steps described at Gradle Plugin Portal page.