"The filename or extension is too long error" using gradle

Solution 1:

Just add this plugin ManifestClasspath in your build.gradle file and specify the manifest classpath. ManifestClasspath plugin creates a manifest jar for jar files in the classpath of JavaExec task and sets the classpath with the manifest jar.

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
    id "com.github.ManifestClasspath" version "0.1.0-RELEASE"       
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
mainClassName = 'com.example.demo.Application'
dependencies {

 }

Solution 2:

I had similar problem, in my situation this works fine:

 task pathingJar(type: Jar) {
      dependsOn configurations.runtime
      appendix = 'pathing'

      doFirst {
         manifest {
             attributes "Class-Path": configurations.runtime.files.collect {it.toURL().toString().replaceFirst("file:/", '/')}.join(" ")
         }
     }
 }
 bootRun {
     dependsOn pathingJar
     doFirst {
         classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
     }
 }

Solution 3:

If you use JetBrains Intellij Idea, you could solve it with one simple setting. Go to Run/Debug configuration and set Shorten command line to "JAR manifest". You should set it for each configuration you run, though.

enter image description here