Skip to content

Commit f43a0b4

Browse files
committed
Fix configuration of environment in Kotlin bootBuildImage examples
Fixes gh-22913
1 parent 5e5c1fb commit f43a0b4

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ task dependencyVersions(type: org.springframework.boot.build.constraints.Extract
7272

7373
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
7474
dependsOn dependencyVersions
75+
inputs.dir('src/docs/gradle').withPathSensitivity(PathSensitivity.RELATIVE)
7576
doFirst {
7677
attributes "dependency-management-plugin-version": dependencyVersions.versionConstraints["io.spring.gradle:dependency-management-plugin"]
7778
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ bootBuildImage {
1515
]
1616
}
1717
// end::env[]
18+
19+
task bootBuildImageEnvironment {
20+
doFirst {
21+
bootBuildImage.environment.each { name, value -> println "$name=$value" }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import org.springframework.boot.gradle.tasks.bundling.BootJar
1+
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
22

33
plugins {
44
java
55
id("org.springframework.boot") version "{gradle-project-version}"
66
}
77

8-
tasks.getByName<BootJar>("bootJar") {
9-
mainClassName = "com.example.ExampleApplication"
10-
}
11-
128
// tag::env[]
139
tasks.getByName<BootBuildImage>("bootBuildImage") {
14-
environment = [
15-
"HTTP_PROXY" : "http://proxy.example.com",
16-
"HTTPS_PROXY" : "https://proxy.example.com"
17-
]
10+
environment = mapOf("HTTP_PROXY" to "http://proxy.example.com",
11+
"HTTPS_PROXY" to "https://proxy.example.com")
1812
}
1913
// end::env[]
14+
15+
tasks.register("bootBuildImageEnvironment") {
16+
doFirst {
17+
for((name, value) in tasks.getByName<BootBuildImage>("bootBuildImage").environment) {
18+
print(name + "=" + value)
19+
}
20+
}
21+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ bootBuildImage {
1212
environment = ["BP_JVM_VERSION" : "13.0.1"]
1313
}
1414
// end::env[]
15+
16+
task bootBuildImageEnvironment {
17+
doFirst {
18+
bootBuildImage.environment.each { name, value -> println "$name=$value" }
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import org.springframework.boot.gradle.tasks.bundling.BootJar
1+
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
22

33
plugins {
44
java
55
id("org.springframework.boot") version "{gradle-project-version}"
66
}
77

8-
tasks.getByName<BootJar>("bootJar") {
9-
mainClassName = "com.example.ExampleApplication"
10-
}
11-
128
// tag::env[]
139
tasks.getByName<BootBuildImage>("bootBuildImage") {
14-
environment = ["BP_JVM_VERSION" : "13.0.1"]
10+
environment = mapOf("BP_JVM_VERSION" to "13.0.1")
1511
}
1612
// end::env[]
13+
14+
tasks.register("bootBuildImageEnvironment") {
15+
doFirst {
16+
for((name, value) in tasks.getByName<BootBuildImage>("bootBuildImage").environment) {
17+
print(name + "=" + value)
18+
}
19+
}
20+
}
21+

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.jar.Manifest;
2929
import java.util.zip.ZipEntry;
3030

31+
import org.gradle.testkit.runner.BuildResult;
3132
import org.junit.jupiter.api.TestTemplate;
3233
import org.junit.jupiter.api.extension.ExtendWith;
3334

@@ -221,6 +222,21 @@ void bootJarLayeredExcludeTools() throws IOException {
221222
}
222223
}
223224

225+
@TestTemplate
226+
void bootBuildImageWithCustomBuildpackJvmVersion() throws IOException {
227+
BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-env")
228+
.build("bootBuildImageEnvironment");
229+
assertThat(result.getOutput()).contains("BP_JVM_VERSION=13.0.1");
230+
}
231+
232+
@TestTemplate
233+
void bootBuildImageWithCustomProxySettings() throws IOException {
234+
BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-env-proxy")
235+
.build("bootBuildImageEnvironment");
236+
assertThat(result.getOutput()).contains("HTTP_PROXY=http://proxy.example.com")
237+
.contains("HTTPS_PROXY=https://proxy.example.com");
238+
}
239+
224240
protected void jarFile(File file) throws IOException {
225241
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) {
226242
jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));

0 commit comments

Comments
 (0)