Gradle deploy task - Cannot run program "serverless" error=2, No such file or directory

Hi,

I have created my serverless application and have been testing it using the serverless command directly from the command line (e.g. serverless deploy) and everything is working as expected, now I have switched over to try to use the gradle deploy task that was automatically created by the serverless template I picked (aws-kotlin-jvm-gradle) but it fails with the following stacktrace;

Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'serverless''
            at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:222)
            at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:202)
            at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:342)
            at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
            at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
            ... 3 more
    Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'serverless'
            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:68)
            ... 4 more
    Caused by: java.io.IOException: Cannot run program "serverless" (in directory "/Users/johnbartlett/workspace/test-project"): error=2, No such file or directory
            at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
            ... 6 more
    Caused by: java.io.IOException: error=2, No such file or directory
            ... 7 more

The directory mentioned in the stacktrace is where I am running the serverless commands directly from the command line (e.g /Users/johnbartlett/workspace/test-project) and it works.

Does anyone have any ideas why this might be happening?

UPDATE

By changing the default gradle deploy task to;

task deploy(type: Exec, dependsOn:'shadowJar') {
 commandLine 'usr/local/bin/serverless', 'deploy'
}

it seems to work! Why does it seem to require the full path to the program when it’s on the path and I can run it directly from the command line without the full path?

UPDATE 2

After changing it to the full path after a few runs I decided to try and switch it back and now it appears to be working… at a bit of a loss but I can only assume its environment based.

Thanks,
John

1 Like