aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.6k stars 1.18k forks source link

Bug: gradle-8.10-bin+ causing IOException #7864

Open TriNextErik opened 3 months ago

TriNextErik commented 3 months ago

Description:

When the distributionUrl in the gradle-wrapper.properties of a project is set to https\://services.gradle.org/distributions/gradle-8.10-bin.zip or higher versions, an IOException occurs during the build process.

Steps to reproduce:

1.) Create a new Project in IntelliJ IDEA 2024.2.3 (Ultimate Edition) 2.) Edit the distributionUrl in the gradle-wrapper.properties from: https\://services.gradle.org/distributions/gradle-8.8-bin.zip to https\://services.gradle.org/distributions/gradle-8.10-bin.zip 3.) Add implementation("com.amazonaws:aws-lambda-java-core:1.2.3") to the dependencies 4.) Use the following class class/code and run the local webhook

public class LambraEntryPoint implements RequestStreamHandler {

    /**
     * Handles a Lambda Function request
     *
     * @param input The Lambda Function input stream
     * @param output The Lambda function output stream
     * @param context The Lambda execution environment context object.
     */
    @Override
    public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
    }
}

Observed result:

Result was tested on gradle-8.8-bin.zip and gradle-8.12.1-bin.zip

2025-02-05 11:32:34,658 | Running workflow 'JavaGradleWorkflow'
2025-02-05 11:32:34,658 |  Running JavaGradleWorkflow:GradleBuild
2025-02-05 11:32:35,619 | JavaGradleWorkflow:GradleBuild failed
Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\workflows\java_gradle\actions.py", line 50, in _build_project
    self.subprocess_gradle.build(
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\workflows\java_gradle\gradle.py", line 45, in build
    raise GradleExecutionError(message=stderr.decode("utf8").strip())
aws_lambda_builders.workflows.java_gradle.gradle.GradleExecutionError: Gradle Failed: FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildLifecycleController using ServicesProvider.createBuildLifecycleController().
   > Could not create service of type BuildModelController using VintageBuildControllerProvider.createBuildModelController().
      > Could not create service of type OutputFilesRepository using ExecutionBuildServices.createOutputFilesRepository().
         > java.io.IOException: Cannot delete file: C:\Users\USER~1\AppData\Local\Temp\tmp83ub653u\gradle-cache\buildOutputCleanup\buildOutputCleanup.lock

Expected result:

Build Succeeded

Additional environment details:

  1. OS: Win 11
  2. sam --version: SAM CLI, version 1.132.0
  3. AWS region: Frankfurt (eu-central-1)
{
  "version": "1.132.0",
  "system": {
    "python": "3.12.6",
    "os": "Windows-11-10.0.22631-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.6",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
vicheey commented 2 months ago

Thank you for reporting the issue. We will try to reproduce the issue.

vicheey commented 1 month ago

@TriNextErik To help with reproducing the bug accurately, do you mind providing sample project along with your template.yaml?

TriNextErik commented 1 month ago

If we're talking about the temp-template.yaml it looks like the following:

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      Timeout: 300
      MemorySize: 128
      Handler: LambraEntryPoint::handleRequest
      CodeUri: C:\Users\MyUser\IdeaProjects\LambraEntryPoint\LambraEntryPoint\LambraEntryPoint
      Runtime: java21
      Architectures:
        - x86_64

Otherwise I don't know what other information I could provide. I just followed the steps I mentioned above. This is my Project structure:

Image

Run config:

Image