File Name Too Long

When trying to build the Spring Boot source code, I ran into a strange problem: The Gradle build terminated with several “File name too long” exceptions. I knew that the ext4 filesystem I was using has limits – 4064 characters for the entire path and 255 characters for each segment. But I didn’t seem to hit that limit. Something strange was going on.

This was the error message I encountered:

Build file '/home/matthias/IdeaProjects/spring-boot/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle'

* What went wrong:
Could not compile build file '/home/matthias/IdeaProjects/spring-boot/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle'.
> startup failed:
  /home/matthias/.gradle/caches/7.3.3/scripts/datpeaugopjrqeo19w9544ugq/proj/_BuildScript_$_run_closure1$_closure2$_closure5$_closure8$_closure10$_closure15$_closure24$_closure54$_closure59$_closure61$_closure62$_closure63.class (File name too long)

Very weird, the filename is only 151 characters!

It turns out that because I’m using an encrypted home directory via Gvfs, the actual filenames are longer. This makes sense, you can’t expect the encrypted filename to be the same size as the unencrypted one. In fact, all filenames should be the same size so that it’s impossible to deduct anything from file lenghts.

The solution was rather simple if unsatisfying: Move the Gradle directory outside the encrypted home directory. Example:

$ mkdir -p /var/tmp/matt/gradle
$ export GRADLE_USER_HOME=/var/tmp/matt/gradle

You can set the envrionment variable in your ~/.profile file or similar to make it persistent.

This entry was posted in linux and tagged , . Bookmark the permalink.

1 Response to File Name Too Long

  1. vaiola kail says:

    Try “Long Path Tool” or Gs Richcopy 360 , both can handle the problem of long pathnames

Leave a comment