diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc index 0a17d342c0b..85c137ae599 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging-oci-image.adoc @@ -59,7 +59,7 @@ The following table summarizes the available properties and their default values | `imageName` | `--imageName` | {spring-boot-api}/buildpack/platform/docker/type/ImageReference.html#of-java.lang.String-[Image name] for the generated image. -| `docker.io/library/${project.artifactId}:${project.version}` +| `docker.io/library/${project.name}:${project.version}` | `environment` | @@ -149,7 +149,7 @@ include::../gradle/packaging/boot-build-image-env-proxy.gradle.kts[tags=env] [[build-image-example-custom-image-name]] ==== Custom Image Name -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}`. +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}`. You can take control over the name by setting task properties, as shown in the following example: [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle index 5212fd96777..c1893e37d92 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle @@ -3,12 +3,14 @@ plugins { id 'org.springframework.boot' version '{gradle-project-version}' } -bootJar { - mainClassName 'com.example.ExampleApplication' -} - // tag::image-name[] bootBuildImage { - imageName = "example.com/library/${project.artifactId}" + imageName = "example.com/library/${project.name}" } // end::image-name[] + +task bootBuildImageName { + doFirst { + println(tasks.bootBuildImage.imageName) + } +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle.kts index b100e7071da..e7f21592b70 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle.kts +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-build-image-name.gradle.kts @@ -1,16 +1,18 @@ -import org.springframework.boot.gradle.tasks.bundling.BootJar +import org.springframework.boot.gradle.tasks.bundling.BootBuildImage plugins { java id("org.springframework.boot") version "{gradle-project-version}" } -tasks.getByName("bootJar") { - mainClassName = "com.example.ExampleApplication" -} - // tag::image-name[] tasks.getByName("bootBuildImage") { - imageName = "example.com/library/${project.artifactId}" + imageName = "example.com/library/${project.name}" } // end::image-name[] + +tasks.register("bootBuildImageName") { + doFirst { + println(tasks.getByName("bootBuildImage").imageName) + } +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java index 58f811b3bdb..26b7f1e1132 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java @@ -237,6 +237,13 @@ class PackagingDocumentationTests { .contains("HTTPS_PROXY=https://proxy.example.com"); } + @TestTemplate + void bootBuildImageWithCustomImageName() throws IOException { + BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-name") + .build("bootBuildImageName"); + assertThat(result.getOutput()).contains("example.com/library/" + this.gradleBuild.getProjectDir().getName()); + } + protected void jarFile(File file) throws IOException { try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) { jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));