liveBook · Manning

Spring Boot Maven plugin

As explained in Spring in Action, Sixth Edition

The Spring Boot Maven plugin integrates Spring Boot application packaging and execution tasks into Maven builds.

The Spring Boot Maven plugin connects a Spring Boot application to Maven build tasks. It lets you run the application during development, package it as an executable JAR, and build a container image. section 1.2.2 section 18.3

For an executable JAR, the plugin:

  • Provides a Maven goal for running the application. section 1.2.2
  • Includes dependency libraries in the JAR so they are available at runtime. section 1.2.2
  • Writes a manifest identifying the application’s bootstrap class as the JAR’s main class. section 1.2.2

Run or package an application

From the project directory, run `./mvnw spring-boot:run` to start the application through Maven. To make and launch an executable JAR, run `./mvnw package`, then `java -jar target/taco-cloud-0.0.1-SNAPSHOT.jar`. section 1.2.2

For deployment, `mvnw spring-boot:build-image` builds a container image without a separate Dockerfile. Docker must be installed on the build machine. The default image tag uses the project’s artifact ID and version; supply `-Dspring-boot.build-image.imageName=tacocloud/tacocloud:0.0.19-SNAPSHOT` when you need a repository-specific name. section 18.3

<plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 <configuration>
   <image>
     <name>tacocloud/${project.artifactId}:${project.version}</name>
   </image>
 </configuration>
</plugin>

The plugin configuration sets an image name using Maven project properties, so the tag follows the artifact ID and version. section 18.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Shows Maven commands and image-name configuration, but does not detail the plugin’s implementation.
Examples
Uses Maven wrapper commands to run and package an application, then builds an image with a custom tag.
What it assumes
Assumes a Spring Boot Maven project and requires Docker on the machine that builds container images.
What you can do after
Operate/configure it to run an application, produce an executable JAR, or build a Docker image with a chosen name.
How it connects
Links Maven goals to executable JARs, application bootstrap classes, Docker images, and image registries.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.