Gradle 1.10 exec raises "no such file or directory" for executing npm

On Ubuntu Saucy:

npm can be installed using nvm for the sake of this example. It puts a symbolic link “npm” on the PATH, pointing to a js file.

task npm(type:Exec) {

commandLine ‘npm’ }

This works fine with gradle 1.9, but in 1.10 I get:

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:npm’.

Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process ‘command ‘npm’’

at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:192)

at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:321)

at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:88)

… 1 more Caused by: java.io.IOException: Cannot run program “npm” (in directory “/home/user/path”): error=2, No such file or directory

at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:69)

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

… 2 more

There are 2 issues. The first is that this commands now fails, which is bad enough. But the StackTrace also seems weird and useless (java has no business looking for any file in that directory), so it seems this is some fallback failing. If so, the debug log should indicate that the original call failed.

I can still run shell command like

task npm(type:Exec) {

commandLine ‘ls’, ‘-al’ }

or even

task npm(type:Exec) {

commandLine ‘which’, ‘npm’ }

which returns the path to the executable.

Note that this works in 1.10, though:

task foo(type:Exec) {

commandLine ‘/home/kruset/.nvm/v0.11.10/bin/npm’ }

With a relative path as well.

For the time being, the only solution I found to run npm is like this

task npmInstall << {

// Gradle Exec Task fails to run npm

Runtime.getRuntime().exec(“npm install”, null, file(’.’)); }

BTW I tried using the gradle-grunt-plugin, but it has the same problems since it uses the ExecSpec

Actually the workaround should at least be in doLast{}, I guess.

And BTW, I also tried running gvm that way, and failed with both 1.9 and 1.10. This also fails using the Java Runtime.exec approach, interestingly also with “java.io.IOException: error=2, No such file or directory”, though maybe that’s caused by the empty environment argument

Hi Thibault,

I can’t reproduce this. Could you provide a complete build script that exhibits this problem? (i.e. works on 1.9 and fails on 1.10).

The code in the original post is a complete build script.

‘’'task npm(type:Exec) {

commandLine ‘npm’ }’’’

However when trying now to reproduce on a different computer, this fails for both gradle 1.9 and 1.10, so maybe that was a fluke. I will try and see again with the original computer.

ah, sorry, the second computer had no npm installed. I installed it, and now I can reproduce the same behavior. Works under 1.9, fails under 1.10.

Something else is going on here. This works perfectly fine for me with Gradle 1.10.

I suspect it’s something environmental. Perhaps ‘npm’ is a symlink on your path?

After checking again, it seems I just had my PATH messed up somehow. No sure how. Probably this is invalid then. I cannot reproduce this behavior when the npm is on the PATH. So you may close this as invalid.

Thanks.

If you run gradle as a daemon, it’ll keep the environment from the time you started the daemon. Setting your PATH later on doesn’t affect gradle runs. Kill your gradle daemon to pick up your new $PATH.

1 Like