// required variables: // build_system - maven or gradle // build_name // build_version // optional variables: // network_container - if the generated Docker container needs to run on the same network as an external dependency, this is the name of that container dependency // omit_native_build - set if the native compilation section is not to be rendered ifeval::["{build_system}" == "gradle"] // jar :jar_build_command: ./gradlew clean build :jar_run_command: java -jar build/libs/{build_name}-{build_version}.jar // docker container :image_build_command: ./gradlew bootBuildImage ifdef::network_container[] :image_run_command: docker run --network container:{network_container} docker.io/library/{build_name}:{build_version} endif::[] ifndef::network_container[] :image_run_command: docker run docker.io/library/{build_name}:{build_version} endif::[] // native :native_build_command: ./gradlew nativeCompile :native_run_command: build/native/nativeCompile/{build_name} // native docker container :native_image_build_command: ./gradlew bootBuildImage ifdef::network_container[] :native_image_run_command: docker run --network container:{network_container} docker.io/library/{build_name}:{build_version} endif::[] ifndef::network_container[] :native_image_run_command: docker run docker.io/library/{build_name}:{build_version} endif::[] endif::[] ifeval::["{build_system}" == "maven"] // jar :jar_build_command: ./mvnw clean package :jar_run_command: java -jar target/{build_name}-{build_version}.jar // docker container :image_build_command: ./mvnw spring-boot:build-image ifdef::network_container[] :image_run_command: docker run --network container:{network_container} docker.io/library/{build_name}:{build_version} endif::[] ifndef::network_container[] :image_run_command: docker run docker.io/library/{build_name}:{build_version} endif::[] // native :native_build_command: ./mvnw -Pnative native:compile :native_run_command: target/{build_name} // native docker container :native_image_build_command: ./mvnw -Pnative spring-boot:build-image ifdef::network_container[] :native_image_run_command: docker run --network container:{network_container} docker.io/library/{build_name}:{build_version} endif::[] ifndef::network_container[] :native_image_run_command: docker run docker.io/library/{build_name}:{build_version} endif::[] endif::[] == Building the Application This section describes different ways to run this guide: 1. https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems[Building and executing a JAR file] 2. https://docs.spring.io/spring-boot/docs/current/reference/html/container-images.html#container-images.buildpacks[Building and executing a Docker container using Cloud Native Buildpacks^] ifndef::omit_native_build[] 3. https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.native-build-tools[Building and executing a native image^] 4. https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks[Building and executing a native image container using Cloud Native Buildpacks^] endif::[] Regardless of how you choose to run the application, the output should be the same. To run the application, you can package the application as an executable jar. The `{jar_build_command}` command compiles the application to an executable jar. You can then run the jar with the `{jar_run_command}` command. Alternatively, if you have a Docker environment available, you could create a Docker image directly from your Maven or Gradle plugin, using buildpacks. With https://docs.spring.io/spring-boot/docs/current/reference/html/container-images.html#container-images.buildpacks[Cloud Native Buildpacks^], you can create Docker compatible images that you can run anywhere. Spring Boot includes buildpack support directly for both Maven and Gradle. This means you can type a single command and quickly get a sensible image into a locally running Docker daemon. To create a Docker image using Cloud Native Buildpacks, run the `{image_build_command}` command. With a Docker environment enabled, you can run the application with the `{image_run_command}` command. ifdef::network_container[] NOTE: The `--network` flag tells Docker to attach our guide container to the existing network that our external container is using. You can find more information in the https://docs.docker.com/network/#container-networks[Docker documentation^]. endif::[] ifndef::omit_native_build[] === Native Image Support Spring Boot also supports https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.introducing-graalvm-native-images[compilation to a native image^], provided you have a GraalVM distribution on your machine. ifeval::["{build_system}" == "gradle"] To create a https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.native-build-tools.gradle[native image with Gradle^] using Native Build Tools, first make sure that your Gradle build contains a `plugins` block that includes `org.graalvm.buildtools.native`. ---- plugins { id 'org.graalvm.buildtools.native' version '0.9.28' ... ---- endif::[] You can then run the `{native_build_command}` command to generate a native image. When the build completes, you will be able to run the code with a near-instantaneous start up time by executing the `{native_run_command}` command. ifeval::["{build_system}" == "maven"] To create https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks.maven[native image container using Maven] you should ensure that your `pom.xml` file uses the `spring-boot-starter-parent` and the `org.graalvm.buildtools:native-maven-plugin`. This plugin should be located in the ` ` section: ---- org.graalvm.buildtools native-maven-plugin ---- endif::[] You can also create a https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks[Native Image using Buildpacks^]. You can generate a native image by running the `{native_image_build_command}` command. Once the build completes, you can start your application with the `{native_image_run_command}` command. endif::[] //end omit_native_build