Skip to content

Incorrect JAVA_HOME for custom Corretto runtime on AL 2023 x86_64 #738

@naiyerasif

Description

@naiyerasif

Describe the bug
When I provision a CodeBuild project with Amazon Linux 2023 x86_64 standard:5.0, and set the runtime as corretto22 in the install phase, the exported JAVA_HOME, JRE_HOME, and JDK_HOME variables don't point to the correct installed location of Corretto 22, causing failure when I try to run mvn package in the next phases.

To Reproduce
Steps to reproduce the behavior:

  1. Create a CodeBuild project with Amazon Linux 2023 x86_64 standard:5.0 image. (I'm using this to build a Java application with Maven with source and target set to 22 in pom.xml)
  2. Specify corretto22 as the runtime version
    version: 0.2
    phases:
      install:
        runtime-versions:
          java: corretto22
      build:
        commands:
          - mvn package
  3. Trigger a job. It fails during build phase. Maven complains that JAVA_HOME is not set correctly.

Expected behavior
The commands in build phase should pass and Maven should not complain about JAVA_HOME

Logs
NA

Platform (please complete the following information):

  • OS: Amazon Linux 2023 x86_64 standard:5.0

Additional context
The issue seems to stem from here.

# https://github.com/aws/aws-codebuild-docker-images/blob/1bd6ad2e247b957c8597fc31e172e3d2df185a19/al2/x86_64/standard/5.0/runtimes.yml#L66
default:
  commands:
    - echo "Installing custom Corretto(OpenJDK) version $VERSION ..."
    - yum -y install java-$VERSION-amazon-corretto-devel.x86_64
    - export JAVA_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - export JRE_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - export JDK_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - |-
      for tool_path in "$JAVA_HOME"/bin/*;
        do tool=`basename "$tool_path"`;
          if [ $tool != 'java-rmi.cgi' ];
            then
              rm -f /usr/bin/$tool /var/lib/alternatives/$tool \
                && update-alternatives --install /usr/bin/$tool $tool $tool_path 20000;
          fi;
      done

In the above runtime configuration, JAVA_HOME, JRE_HOME, and JDK_HOME are all pointing to "/usr/lib/jvm/java-$VERSION-amazon-corretto" whereas Corretto 22 installs at "/usr/lib/jvm/java-$VERSION-amazon-corretto.x86_64".

Current workaround
Manually overriding the environment variables to point to correct location of Corretto 22 fixes the issue and things start working.

version: 0.2
  phases:
    install:
      runtime-versions:
        java: corretto22
      commands:
        - JAVA_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto.x86_64"
        - JRE_HOME=${JAVA_HOME}
        - JDK_HOME=${JAVA_HOME}
    build:
      commands:
        - mvn package

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions