title: gradle windows java.io.IOException: CreateProcess error=206, filename is too long
body: <p>A couple of solutions to the problem of the windows path being too long are present for gradle:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle">Add classpath in manifest using Gradle</a></li>
  <li><a href="https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle">&quot;The filename or extension is too long error&quot; using gradle</a></li>
  </ul>
  
  <p>However, it is unclear to me how to handle this in a multi project setup. Would all sub-projects with the <code>application</code> plugin require these changes?
  Could this also be specified in the <code>init.gradle</code> file?</p>
  
  <p>Also is there a better workaround?</p>
  
  <p>Apparently <a href="https://github.com/viswaramamoorthy/gradle-util-plugins/" rel="nofollow noreferrer">https://github.com/viswaramamoorthy/gradle-util-plugins/</a> has been published. However, it does not fix the problems for me. The initial java problem is solved - but not correctly. Some classes can no longer be loaded i.e. unit tests be executed in case of scala.</p>
  
  <h1>edit</h1>
  
  <pre><code>experimenting with
  task testPathingJar(type: Jar) {
          appendix = "testPathing"
          doFirst {
              manifest {
              attributes "Class-Path": configurations.testCompile.files.join(" ")
              }
          }
      }
  
      compileTestScala {
          dependsOn(testPathingJar)
          classpath = files(testPathingJar.archivePath)
      }    
  
      task pathingJar(type: Jar) {
          appendix = "pathing"
          doFirst {
              manifest {
              attributes "Class-Path": configurations.compile.files.join(" ")
              }
          }
      }
  
      compileScala {
          dependsOn(pathingJar)
          classpath = files(pathingJar.archivePath)
      }    
  
      build {
          dependsOn pathingJar
          doFirst {
              classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
          }
      }
  </code></pre>
  
  <p>unfortunately fails with during <code>shadowJar</code> as the manifest tricks reported in several of the links seem to have a problem with scala:</p>
  
  <pre><code>Cannot infer Scala class path because no Scala library Jar was found. Does project ':tma-mobility-frequencyCounting' declare dependency to scala-library? Searched classpath: file collection.
  </code></pre>
  
  <p>trying:</p>
  
  <pre><code>    jar {
        manifest {
          attributes(
            "Class-Path": configurations.compileOnly.collect { it.getName() }.join(' '))
        }
      }
  fails for task `shadowDistZip` when executing `gradle build` with:
  
      java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.8.0_131\bin\java.exe" (in directory "D:\users\username\development\projects\projectName\Code\spark\module_name"): CreateProcess error=206, Der Dateiname oder die Erweiterung ist zu lang
  
  moving gradle user home to the root (also the project) of the partition:
  
      .\gradlew.bat build --gradle-user-home D:\projects\gradleHome
  fails with the same error for task `test`.
  
  When trying the strategy of https://github.com/jhipster/generator-jhipster/pull/4324/files like:
  
  task pathingJar(type: Jar) {
      dependsOn configurations.runtime
      appendix = 'pathing'
  
      doFirst {
          manifest {
              attributes 'Class-Path': configurations.runtime.files.collect {
                  it.toURL().toString().replaceFirst(/file:\/+/, '/')
              }.join(' ')
          }
      }
  }
  
  build {
      dependsOn pathingJar
      doFirst {
          classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)        }
  }
  
  task pathingJarTest(type: Jar) {
      dependsOn configurations.runtime
      appendix = 'pathing'
  
      doFirst {
          manifest {
              attributes 'Class-Path': configurations.runtime.files.collect {
                  it.toURL().toString().replaceFirst(/file:\/+/, '/')
              }.join(' ')
          }
      }
  }
  
  test {
      dependsOn pathingJarTest
      doFirst {
          classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJarTest.archivePath)        }
  }
  </code></pre>
  
  <p>Fails with</p>
  
  <pre><code>Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///C:/tmp/projectName/moduleName/reports/tests/test/index.html
  </code></pre>
  
  <p>even though this file never is created</p>
  
  <p>trying one more thing: a fat jar including all the test cases:</p>
  
  <pre><code>task fatTestJar(type: Jar) {
      baseName = project.name + '-test-all'
      from {
          from { configurations.testRuntime.collect { it.isDirectory() ? it : zipTree(it) }}
          from sourceSets.test.output
      }
      with jar
  }
  </code></pre>
  
  <p>however, this does not yet compile.</p>