Skip to content

Commit 28749e7

Browse files
Update CNB buildpack Java version env variable
Prior to this commit, the build tool plugins set the environment variable BP_JAVA_VERSION when invoking the CNB builder to set the version of the JDK/JRE that the builder should use in the created image. With CNB API 0.3, the convention changed the name of this environment variable to BP_JVM_VERSION. This commit updates the build tool plugins to match the newer convention. See gh-21273
1 parent 35bc82a commit 28749e7

File tree

9 files changed

+17
-17
lines changed

9 files changed

+17
-17
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ This configuration will use a builder image with the name `mine/java-cnb-builder
102102
==== Builder Configuration
103103
If the builder exposes configuration options, those can be set using the `environment` property.
104104

105-
The following example assumes that the default builder defines a `BP_JAVA_VERSION` property (typically used to customize the JDK version the image should use):
105+
The following example assumes that the default builder defines a `BP_JVM_VERSION` property (typically used to customize the JDK version the image should use):
106106

107107
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
108108
.Groovy

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-env.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ bootJar {
99

1010
// tag::env[]
1111
bootBuildImage {
12-
environment = ["BP_JAVA_VERSION" : "13.0.1"]
12+
environment = ["BP_JVM_VERSION" : "13.0.1"]
1313
}
1414
// end::env[]

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-env.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ tasks.getByName<BootJar>("bootJar") {
1111

1212
// tag::env[]
1313
tasks.getByName<BootBuildImage>("bootBuildImage") {
14-
environment = ["BP_JAVA_VERSION" : "13.0.1"]
14+
environment = ["BP_JVM_VERSION" : "13.0.1"]
1515
}
1616
// end::env[]

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
public class BootBuildImage extends DefaultTask {
5353

54-
private static final String OPENJDK_BUILDPACK_JAVA_VERSION_KEY = "BP_JAVA_VERSION";
54+
private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION";
5555

5656
private RegularFileProperty jar;
5757

@@ -246,8 +246,8 @@ private BuildRequest customizeEnvironment(BuildRequest request) {
246246
if (this.environment != null && !this.environment.isEmpty()) {
247247
request = request.withEnv(this.environment);
248248
}
249-
if (this.targetJavaVersion.isPresent() && !request.getEnv().containsKey(OPENJDK_BUILDPACK_JAVA_VERSION_KEY)) {
250-
request = request.withEnv(OPENJDK_BUILDPACK_JAVA_VERSION_KEY, translateTargetJavaVersion());
249+
if (this.targetJavaVersion.isPresent() && !request.getEnv().containsKey(BUILDPACK_JVM_VERSION_KEY)) {
250+
request = request.withEnv(BUILDPACK_JVM_VERSION_KEY, translateTargetJavaVersion());
251251
}
252252
return request;
253253
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,23 @@ void whenTheEnvironmentIsSetItReplacesAnyExistingEntriesAndIsIncludedInTheReques
131131

132132
@Test
133133
void whenJavaVersionIsSetInEnvironmentItIsIncludedInTheRequest() {
134-
this.buildImage.environment("BP_JAVA_VERSION", "from-env");
134+
this.buildImage.environment("BP_JVM_VERSION", "from-env");
135135
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8);
136-
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JAVA_VERSION", "from-env").hasSize(1);
136+
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JVM_VERSION", "from-env").hasSize(1);
137137
}
138138

139139
@Test
140140
void whenTargetCompatibilityIsSetThenJavaVersionIsIncludedInTheRequest() {
141141
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8);
142-
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JAVA_VERSION", "8.*").hasSize(1);
142+
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JVM_VERSION", "8.*").hasSize(1);
143143
}
144144

145145
@Test
146146
void whenTargetCompatibilityIsSetThenJavaVersionIsAddedToEnvironment() {
147147
this.buildImage.environment("ALPHA", "a");
148148
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_11);
149149
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a")
150-
.containsEntry("BP_JAVA_VERSION", "11.*").hasSize(2);
150+
.containsEntry("BP_JVM_VERSION", "11.*").hasSize(2);
151151
}
152152

153153
@Test

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-failsWithBuilderError.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10-
environment = ["BP_JAVA_VERSION" : "13.9.9"]
10+
environment = ["BP_JVM_VERSION" : "13.9.9"]
1111
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The builder can be specified on the command line as well, as shown in this examp
146146
==== Builder Configuration
147147
If the builder exposes configuration options using environment variables, those can be set using the `env` attributes.
148148

149-
The following example assumes that the default builder defines a `BP_JAVA_VERSION` property (typically used to customize the JDK version the image should use):
149+
The following example assumes that the default builder defines a `BP_JVM_VERSION` property (typically used to customize the JDK version the image should use):
150150

151151
[source,xml,indent=0,subs="verbatim,attributes"]
152152
----
@@ -160,7 +160,7 @@ The following example assumes that the default builder defines a `BP_JAVA_VERSIO
160160
<configuration>
161161
<image>
162162
<env>
163-
<BP_JAVA_VERSION>13.0.1</BP_JAVA_VERSION>
163+
<BP_JVM_VERSION>13.0.1</BP_JVM_VERSION>
164164
</env>
165165
</image>
166166
</configuration>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-builder-error/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<configuration>
2525
<image>
2626
<env>
27-
<BP_JAVA_VERSION>13.9.9</BP_JAVA_VERSION>
27+
<BP_JVM_VERSION>13.9.9</BP_JVM_VERSION>
2828
</env>
2929
</image>
3030
</configuration>

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
@Execute(phase = LifecyclePhase.PACKAGE)
6464
public class BuildImageMojo extends AbstractPackagerMojo {
6565

66-
private static final String OPENJDK_BUILDPACK_JAVA_VERSION_KEY = "BP_JAVA_VERSION";
66+
private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION";
6767

6868
/**
6969
* Directory containing the JAR.
@@ -175,11 +175,11 @@ private BuildRequest customize(BuildRequest request) {
175175
}
176176

177177
private BuildRequest customizeEnvironment(BuildRequest request) {
178-
if (!request.getEnv().containsKey(OPENJDK_BUILDPACK_JAVA_VERSION_KEY)) {
178+
if (!request.getEnv().containsKey(BUILDPACK_JVM_VERSION_KEY)) {
179179
JavaCompilerPluginConfiguration compilerConfiguration = new JavaCompilerPluginConfiguration(this.project);
180180
String targetJavaVersion = compilerConfiguration.getTargetMajorVersion();
181181
if (StringUtils.hasText(targetJavaVersion)) {
182-
return request.withEnv(OPENJDK_BUILDPACK_JAVA_VERSION_KEY, targetJavaVersion + ".*");
182+
return request.withEnv(BUILDPACK_JVM_VERSION_KEY, targetJavaVersion + ".*");
183183
}
184184
}
185185
return request;

0 commit comments

Comments
 (0)