Ido Ran
Ido Ran

Reputation: 11374

Gradle build fail with Cannot run program No such file or directory

I have a gradle build file with the following task which need to run sphinx-build, I'm running it on Mac OS X with the gradle information bellow.

task makeDocs(type:Exec) {
    workingDir 'sphinx'
    commandLine 'sphinx-build'
    args = ["-b", "html", "-d", "build/doctrees", "-t", "$platformDir", "build/ppsource", "build/html"]
}

When I run this task I get the following exception:

Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'sphinx-build'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
    ... 1 more
Caused by: java.io.IOException: Cannot run program "sphinx-build" (in directory "/Users/idoran/Documents/Seebo/dev/SDK/seebosdk_docs/sphinx"): error=2, No such file or directory
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 3 more
Caused by: java.io.IOException: error=2, No such file or directory

When I run sphinx-build from the same terminal everything works fine.


$ gradle --version

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------

Build time:   2014-11-24 09:45:35 UTC
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_65 (Oracle Corporation 25.65-b01)
OS:           Mac OS X 10.10.5 x86_64

Upvotes: 27

Views: 29539

Answers (5)

Renju Jose
Renju Jose

Reputation: 379

My gradle file contained a snippet to get the aws auth token and I was getting the same failure - Caused by: java.io.IOException: error=2, No such file or directory

In my case, the issue was not caused due to caching.

It was due to gradle not being able to find the aws binary.

What worked for me - Use the which aws command to find the absolute path to aws binary and use it for the binary as shown below. Hope this helps someone with similar issue.

enter image description here

Upvotes: 2

Vampire
Vampire

Reputation: 38619

You shouldn't use commandLine + args together in a Gradle Exec task. Either use commandLine with executable and all arguments as the value, or executable + args which is the better alternative usually.

Upvotes: 7

Joey Harrington
Joey Harrington

Reputation: 300

This error can occur for a couple different reasons. Unfortunately it is not always clear from the error message which one is the problem.

  1. workingDir does not exist. Make sure the specified directory exists before your task runs, or create it in a doFirst block like this:

    task makeDocs(type: Exec) {
        workingDir 'sphinx'
        executable 'sphinx-build'
        args = ["-b", "html", /* other args... */]
    
        doFirst {
            workingDir.mkdirs()
        }
    }
    
  2. The specified executable does not exist or is not on the path. As other answers mention, make sure you are either specifying only commandLine, or both executable and args. So either:

        commandLine "sphinx-build", "-b", "html"
    

    or equivalently,

        executable = "sphinx-build"
        args = ["-b", "html"]
    

Upvotes: 3

Steve-B
Steve-B

Reputation: 668

Try stopping the gradle daemon with ./gradlew --stop

I had the same problem with something as simple as:

commandLine = [ "node", "--version"]

It came down to the gradle daemon having a cached location of node which no longer existed (I had updated node sometime before).

Upvotes: 32

Santosh Kumar Arjunan
Santosh Kumar Arjunan

Reputation: 3896

I had similar issue.. With Vampire's solution, I was able to step up.. However the issue seems to be the sh file not able to point to the exact file location.

Meaning, even with workingDir (wherein actual sh file resides) set properly, still was getting the following exception.

Caused by: java.io.IOException: error=2, No such file or directory

Finally, this post resolved the issue..

Though the original issue of this post's question is already resolved, thought of sharing this solution of adding the absolute file path to actual sh file would resolve the "No such file or directory" issue to someone in the future..

I ran into similar issue and got it resolved with absolute path reference to sh file.

Mine was,

workingDir = "path_to_the_actual_sh_file_to_be_executed"
executable = new File(workingDir, 'actual.sh')
args = ['configure', 'manageRepo', '-tenant', 'etc...']

Upvotes: 6

Related Questions