How to reduce names of .class files created in gradle cache (to avoid file path too long related errors)

The intermediate .class files that Gradle creates under gradle cache while building the java code, is too long. Since most windows apis do not support more than 260 chars of file path length, so some intermediate processes of our custom build system (that runs on windows os) fails.

To that effect, I have following questions:

  1. Is there any way by which the file path length can be reduced?
  2. What determines that how many _closure’x’ will be present in name of any .class file.
  3. Is it possible to make the gradle produce this intermediate .class file with a little modified naming for saving characters - something like $_run_c33_c123… instead of $_run_closure33_closure123…

I’m referring to a path similar to:


Any help in this direction would be much appreciated.


  1. I’m using Gradle 2.2.1
  2. The above path is copied from another thread, just to indicate what intermediate .class files I’m refering to.
  3. I’m also interested in understanding about what exactly ProjectScript, DefaultScript, no_buildscript means…

Those files are compiled versions of the build.gradle files. The ‘closure_#’ names come from Groovy compilation, so we don’t have any control over that. Changing this on the Groovy side would be a breaking change.

Basically, in Groovy, when you do something like:

someMethod { list ->
  // passing a closure
  list.each { item ->
      // another closure
      item.each { subitem ->
           // another closure
           subitem.anotherMethod( { /* some other closure */ } )

All of the closures get compiled into separate classfiles with a name similar to what you’re seeing.

To workaround it, you could move the gradle cache to another directory (e.g., C:.gradle) and reduce the nesting of closures.

Thanks for the reply.
I was able to reduce the path length by moving the gradle cache to another smaller path location, and also by renaming the script’s name which had all the tasks to a smaller name.