Skip to content

Commit d452bbb

Browse files
committed
Merge pull request #22918 from jnizet
* pr/22918: Fix custom image name example and documentation Closes gh-22918
2 parents b1e631e + 27528fd commit d452bbb

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The following table summarizes the available properties and their default values
5959
| `imageName`
6060
| `--imageName`
6161
| {spring-boot-api}/buildpack/platform/docker/type/ImageReference.html#of-java.lang.String-[Image name] for the generated image.
62-
| `docker.io/library/${project.artifactId}:${project.version}`
62+
| `docker.io/library/${project.name}:${project.version}`
6363

6464
| `environment`
6565
|
@@ -149,7 +149,7 @@ include::../gradle/packaging/boot-build-image-env-proxy.gradle.kts[tags=env]
149149

150150
[[build-image-example-custom-image-name]]
151151
==== Custom Image Name
152-
By default, the image name is inferred from the `artifactId` and the `version` of the project, something like `docker.io/library/${project.artifactId}:${project.version}`.
152+
By default, the image name is inferred from the `name` and the `version` of the project, something like `docker.io/library/${project.name}:${project.version}`.
153153
You can take control over the name by setting task properties, as shown in the following example:
154154

155155
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ plugins {
33
id 'org.springframework.boot' version '{gradle-project-version}'
44
}
55

6-
bootJar {
7-
mainClassName 'com.example.ExampleApplication'
8-
}
9-
106
// tag::image-name[]
117
bootBuildImage {
12-
imageName = "example.com/library/${project.artifactId}"
8+
imageName = "example.com/library/${project.name}"
139
}
1410
// end::image-name[]
11+
12+
task bootBuildImageName {
13+
doFirst {
14+
println(tasks.bootBuildImage.imageName)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
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::image-name[]
139
tasks.getByName<BootBuildImage>("bootBuildImage") {
14-
imageName = "example.com/library/${project.artifactId}"
10+
imageName = "example.com/library/${project.name}"
1511
}
1612
// end::image-name[]
13+
14+
tasks.register("bootBuildImageName") {
15+
doFirst {
16+
println(tasks.getByName<BootBuildImage>("bootBuildImage").imageName)
17+
}
18+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ void bootBuildImageWithCustomProxySettings() throws IOException {
237237
.contains("HTTPS_PROXY=https://proxy.example.com");
238238
}
239239

240+
@TestTemplate
241+
void bootBuildImageWithCustomImageName() throws IOException {
242+
BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-name")
243+
.build("bootBuildImageName");
244+
assertThat(result.getOutput()).contains("example.com/library/" + this.gradleBuild.getProjectDir().getName());
245+
}
246+
240247
protected void jarFile(File file) throws IOException {
241248
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) {
242249
jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));

0 commit comments

Comments
 (0)