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 96d6a69f63f..728a3220ff7 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 @@ -19,13 +19,13 @@ The following table shows the environment variables and their values: |=== | Environment variable | Description -| DOCKER_HOST +| DOCKER_HOST | URL containing the host and port for the Docker daemon - e.g. `tcp://192.168.99.100:2376` -| DOCKER_TLS_VERIFY +| DOCKER_TLS_VERIFY | Enable secure HTTPS protocol when set to `1` (optional) -| DOCKER_CERT_PATH +| DOCKER_CERT_PATH | Path to certificate and key files for HTTPS (required if `DOCKER_TLS_VERIFY=1`, ignored otherwise) |=== @@ -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}` | `pullPolicy` | `--pullPolicy` @@ -155,7 +155,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 3afe0f2f39b..67742791b8e 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 @@ -235,6 +235,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"));