Describe the bug
Running Lambda function in Gradle Project fails with "SAM build command failed"
To reproduce
build.gradle and right click Import Gradle ProjectApp.java and click Lambda icon on the left of the class definition.Run '[Local] App'Run, but it fails with "SAM build command failed"Build Output details is below.
/usr/local/bin/sam build --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template381.yaml --build-dir /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild1175
Build Failed
2019-03-28 21:41:51 Building resource 'Function'
Error: Unable to find a supported build workflow for runtime 'java8'. Reason: None of the supported manifests '['build.gradle', 'pom.xml']' were found in the following paths '['/Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main', '/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T']'
Expected behavior
The expected behavior is same as "Running a function locally" on AWS Toolkit for IntelliJ – Now generally available \| AWS Developer Blog
Screenshots




Your Environment
Additional context
Can you please attach the contents of the temp file /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template381.yaml?
@K1-Style It seems the root cause is because you checked Create separate module per source set option when import the Gradle project. Try again without checking that option should fix the problem.
@zhangzhx
I tried again without "Create separate module per source set" checking, but it fails similarly.
Gradle Settings is below :

@abrooksv
The result of running the above is below:
/usr/local/bin/sam build --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template.yaml --build-dir /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild
2019-03-29 09:51:53 Building resource 'Function'
Error: Unable to find a supported build workflow for runtime 'java8'. Reason: None of the supported manifests '['build.gradle', 'pom.xml']' were found in the following paths '['/Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main', '/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T']'
Build Failed
/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template.yaml
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
Handler: helloworld.App
CodeUri: /Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main
Runtime: java8
Timeout: 900
Okay, I understand what is wrong.
You can also invoke a Lambda function through the existing template.yaml (That SAM generated in your project root). That should not suffer from the same incorrect CodeUri issue
@abrooksv Thank you for your answer.
I tried below, and confirmed that it successed.
App.java and click Lambda icon on the left of the class definition.Run '[Local] App'From template: and Select this project's template.yamlRun
Build Output details is below.
/usr/local/bin/sam local invoke --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild/template.yaml --event "/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/[Local] App-event.json" HelloWorldFunction
2019-03-29 21:40:51 Found credentials in environment variables.
2019-03-29 21:40:52 Invoking helloworld.App::handleRequest (java8)
Fetching lambci/lambda:java8 Docker container image......
2019-03-29 21:40:54 Mounting /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild/HelloWorldFunction as /var/task:ro inside runtime container
START RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb Version: $LATEST
END RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb
{"body":"{ \"message\": \"hello world\", \"location\": \"X.X.X.X\" }","headers":{"X-Custom-Header":"application/json","Content-Type":"application/json"},"statusCode":200}
REPORT RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb Duration: 2236.87 ms Billed Duration: 2300 ms Memory Size: 128 MB Max Memory Used: 11 MB
That is good to hear, you can also go through the template's gutter icon to auto fill in some of that information:

Thanks, it also works.
This fix has been released in stable version 1.3. Feel free to reopen if you still see any issues.
Thanks! I'm grateful to your support.
Most helpful comment
This fix has been released in stable version 1.3. Feel free to reopen if you still see any issues.