AWS CodeBuild supports Amazon Corretto 17 (Java 17)

The AWS CodeBuild image aws/codebuild/standard:6.0 (software.amazon.awscdk.services.codebuild.LinuxBuildImage.STANDARD_6_0) ships with installed Amazon Corretto 17.

To provision CodeBuild with Java CDK use recent CDK and constructs versions:


<dependency>
    <groupId>software.amazon.awscdk</groupId>
    <artifactId>aws-cdk-lib</artifactId>
    <version>2.32.1</version>
</dependency>
<dependency>
    <groupId>software.constructs</groupId>
    <artifactId>constructs</artifactId>
    <version>3.4.40</version>
</dependency>

Now you can provision a CodeBuild image with Java 17 support:


import software.amazon.awscdk.services.codebuild.LinuxBuildImage;
import software.amazon.awscdk.services.codebuild.PipelineProject;
import software.amazon.awscdk.services.codebuild.BuildEnvironment;
import software.amazon.awscdk.services.codebuild.ComputeType;

//...
PipelineProject.Builder.create(this, "PipelineProject")
        .projectName("Corretto 17")
        //...
        .environment(BuildEnvironment.builder()
                    .computeType(ComputeType.SMALL)
                    .buildImage(LinuxBuildImage.STANDARD_6_0)
                .build())
        .build();

Amazon Corretto 17 becomes directly available in the buildspec.yml without any additional installation:


version: 0.2
env:
  variables:
    JAVA_HOME: "/usr/lib/jvm/java-17-amazon-corretto/"
phases:
    build:
        commands:
            - java -version
            - mvn package    

The JAVA_HOME variable declared in the env section forces Apache Maven to use the installed Amazon Corretto 17.

You can list all available build images with the following command: aws codebuild list-curated-environment-images

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments
License