The OpenJDK buildpack can be configured to use a specific JRE or JDK version by providing the environment variable $BP_JAVA_VERSION to the builder.

The spring-boot:build-image Maven goal and bootBuildImage Gradle task should set $BP_JAVA_VERSION to match the target Java version used by the build (e.g. the equivalent of maven.compiler.target or java.version in Maven or targetCompatibility in Gradle).

The OpenJDK buildpack requires versions to be provided as whole numbers with wildcards like 8.* or 11.*. It may be necessary to map Maven or Gradle properties in the form 1.8 to form expected by OpenJDK buildpack.

Comment From: mikesmithson

I was looking at this issue and wanted to take a stab at it. From what I gather, if someone had a gradle configuration like this:

plugins {
    id 'java'
    id 'org.springframework.boot' version '{version}'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8`

bootJar {
    mainClassName 'com.example.ExampleApplication'
}

......

The bootBuildImage task should be configured with the following environment entry without them explicitly declaring this:

bootBuildImage {
    environment = ["BP_JAVA_VERSION" : "8.*"]
}

Comment From: scottfrederick

@mikesmithson Yes, you understand the requirements correctly. We'll do this for both the Gradle and Maven plugins.

I'm already well underway on this issue though. Generally if there's a name under assignees on a GitHub issue, that means someone has already started some work on it.