"The filename or extension is too long error" using gradle
Asked Answered
H

9

46

I have recently updated my code and when I tried to run our application using g bootRun in the command line, I encountered this error.

Stack Trace:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bootRun'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61) Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'C:\Java\jdk1.8.0_77\bin\java.exe''
        at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:197)
        at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:327)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40) Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'C:\Java\jdk1.8.0_77\bin\java.exe'
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
        at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
        at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
        at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
        ... 2 more Caused by: java.io.IOException: Cannot run program "C:\Java\jdk1.8.0_77\bin\java.exe" (in directory "D:\Work\FBXX"): CreateProcess  error=206, The filename or extension is too long
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
        ... 5 more Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
        ... 6 more

Here's the task in gradle:

  bootRun {
    if (project.hasProperty('args')) {
        args project.args.split('\\s+')
    }
  }

We have tried reducing the directory path of our project but we're looking for another solution.

This is the current directory path of our project:

D:\Work\FBXX

Hallvard answered 14/10, 2016 at 7:33 Comment(3)
Have you read https://mcmap.net/q/156337/-createprocess-error-206-the-filename-or-extension-is-too-long-when-running-main-method ?Wallop
Look here: #5434982Haemophilia
You should provide build.gradle file! without it, we can only guess! Did you use something like classpath = files("$buildDir/classes/main"? If so, replace it with sourceSets.main.compileClasspath. In my experience, the former concatenates all .class paths and forms a very long string to be used as an argument to java -classpath command and therefore causes The filename or extension is too long error.Reahard
R
20

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 {

 }
Richie answered 9/4, 2019 at 9:46 Comment(1)
Just adding below to my build.gradle file worked for me: plugins { id "com.github.ManifestClasspath" version "0.1.0-RELEASE" }Aricaarick
C
17

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

Correia answered 19/3, 2020 at 11:11 Comment(2)
Your screenshot is for a Spring Boot application. This question is about running something via gradle. Your answer does not seem relevant to the question.Brougham
Simple and straightforward. Thank you so much for posting this answer, saved the day.Determined
H
16

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)
     }
 }
Haemophilia answered 27/10, 2016 at 10:6 Comment(2)
This worked once I corrected the classpath to classpath = files(sourceSets.main.output.files, pathingJar.archivePath)Randellrandene
This was broken for me. I am using gradle 4.10.3. In gradle 4.x, the runtime configuration is deprecated. I replaced "runtime" with "runtimeClasspath" and it worked.Randellrandene
C
13

Recently I have the same problem and this plugin solved it! https://github.com/viswaramamoorthy/gradle-util-plugins

Chambliss answered 1/8, 2018 at 15:49 Comment(0)
P
1

boot module do this:

if (OperatingSystem.current().isWindows()) {
    task classpathJar(type: Jar) {
        dependsOn configurations.runtime
        appendix = 'classpath'

        doFirst {
            manifest {
                attributes 'Class-Path': configurations.runtime.files.collect {
                    it.toURI().toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
                }.join(' ')
            }
        }
    }

    bootRun {
        dependsOn classpathJar
        doFirst {
            classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", classpathJar.archivePath)
        }
    }
}
Pyrimidine answered 13/2, 2019 at 7:54 Comment(0)
M
1

I have a Grails 3 project working on Windows 8.1 but not in Windows 10. This answer helped me:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
    }
}

apply plugin: "com.github.ManifestClasspath"

Link to gradle plugin

Mackenziemackerel answered 17/9, 2020 at 17:54 Comment(0)
B
1

Even though this post is late, may be it helps someone. In Run --> Edit Configurations --> select the application you want to run --> Build and run --> More options --> Select manifast jar.

It worked under this intellij version ::: 2021.1.2

image

Bousquet answered 23/9, 2021 at 12:32 Comment(0)
A
0

One of the reasons I found the command line was becoming too long was because of some kind of unique id used by gradle in file path.

for example gradle uses jar file el-impl-2.1.2-b03.jar from

C:\Users\bob\.gradle\caches\modules-2\files-2.1\org.glassfish.web\el-impl\2.1.2-b03\6bab1211b6e6b191fdbf06067bd05d2f75a62ac0\el-impl-2.1.2-b03.jar

while the same file in maven is at

C:\Users\bob\.m2\repository\org\glassfish\web\el-impl\2.1.2-b03\el-impl-2.1.2-b03.jar

That is 90 chars vs 150 chars. So if we put the same artifacts in maven, overall size of command line becomes small.

Use these steps to install the jars that can be found in central maven repo to your local maven repo. Then use mavenLocal() as repo in you gradle build file.

Step 1) Create a dependency report

gradlew dependencies > tmp.txt

Step 2) Create a batch file to downloads the dependencies (I use cygwin, if you don't have then use another Linux machine to exeute this command and create install.To.Maven.bat file (note: dos2unix may need to be replaced by fromdos)

cat tmp.txt | tr ' ' '\n' | grep ':' | grep -e org -e com | sort -u  | xargs -n 1 -I fullname echo call mvn  dependency:get -Dartifact=fullname | dos2unix > install.To.Maven.bat

Step 3) Run the bat file to download and install artifacts into local maven repo.

install.To.Maven.bat
Arroba answered 4/10, 2019 at 20:42 Comment(0)
F
0

I too face this problem often. Sometimes just shortening the command line using IntelliJ Edit configurations would solve the issue like mentioned in above comments.

If the above approach didn't work, then simply delete the jar files in the build directory of the project and then it will work.

Foreman answered 6/5, 2021 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.