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


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(
            at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(
            at org.gradle.process.internal.DefaultExecHandle.failed(
            ... 3 more
    Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'serverless'
            at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(
            at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(
            ... 4 more
    Caused by: 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(
            ... 6 more
    Caused by: 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?


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?


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.


1 Like