1. Introduction
Spring Boot Maven plug-in In Apache Maven Spring Boot support is provided. It allows you to package executable jar or war files, run Spring Boot applications, generate build information, and start your Spring Boot applications before running integration tests.
2. Getting started
To use the Spring Boot Maven plug-in, include the appropriate XML in your plugins section pom.xml, as shown in the following example:
<project> <modelVersion>4.0.0</modelVersion> <artifactId>getting-started</artifactId> <!-- ... --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
If you are using milestone or snapshot versions, you also need to add the appropriate pluginRepository element, as shown in the following listing:
<pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>https://repo.spring.io/snapshot</url> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <url>https://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories>
3. Use plug-ins
Maven users can inherit from the spring boot starter parent project to obtain reasonable default values. The parent project provides the following functions:
-
Java 1.8 is the default compiler level.
-
UTF-8 source code.
-
And - parameters
-
The dependency management section inherited from spring boot dependencies POM is used to manage the version of public dependencies< Version > when using these dependencies in your own POM, this dependency management allows you to omit the tags for these dependencies.
-
With execution ID repackage target repackage execution.
-
advisable Resource filtering.
-
Reasonable plug-in configuration( Git submission ID and shade).
-
Make reasonable resource filtering for configuration file specific files (for example, and) and include application.yml application-dev.propertiesapplication-dev.yml
3.1. Inherit Starter Parent POM
To configure your project to inherit from spring boot starter parent, set the following settings:
<!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.6</version> </parent>
With this setting, you can also override various dependencies by overriding the properties in your project. For example, to use different versions of SLF4J library and Spring Data publishing series, you need to add the following content to your pom.xml:
<properties> <slf4j.version>1.7.30</slf4j.version> <spring-data-releasetrain.version>Moore-SR6</spring-data-releasetrain.version> </properties>
3.2. Use Spring Boot without parent POM
You may have reason not to inherit from spring boot starter parent POM. You may have your own company standard parent that you need to use, or you may prefer to explicitly declare all Maven configurations.
If you do not want to use spring boot starter parent, you can still maintain the benefits of dependency management (but not plug-in management) by using import scope dependency, as shown below:
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.5.6</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
The previous example settings do not allow you to override individual dependencies by using properties, as described above. To achieve the same result, you need to add an entry in the dependency management project section before the entry. For example, to use different versions of SLF4J library and Spring Data publishing series, you can add the following elements to your: spring-boot-dependenciespom.xml
<dependencyManagement> <dependencies> <!-- Override SLF4J provided by Spring Boot --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.30</version> </dependency> <!-- Override Spring Data release train provided by Spring Boot --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>2020.0.0-SR1</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.5.6</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
3.3. Override settings on the command line
The plug-in provides many user properties, starting with spring boot, allowing you to customize the configuration from the command line.
For example, you can adjust the configuration file to enable when running the application, as follows:
$ mvn spring-boot:run -Dspring-boot.run.profiles=dev,local
If you want to have default values while allowing it to be overridden on the command line, you should use a combination of user supplied project properties and MOJO configuration.
<project> <properties> <app.profiles>local,dev</app.profiles> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <profiles>${app.profiles}</profiles> </configuration> </plugin> </plugins> </build> </project>
Above, make sure that local and dev are enabled by default. Now a special attribute has been exposed, which can also be overridden on the command line:
$ mvn spring-boot:run -Dapp.profiles=test
4. Objectives
The Spring Boot plug-in has the following goals:
target | describe |
spring-boot:build-image | Use buildpack to package the application into an OCI image. |
spring-boot:build-info | build-info.properties generates the MavenProject file based on the current content. |
spring-boot:help | Displays help information about the spring boot Maven plugin. Call MVN spring boot: Help - ddetail = true - dgoal = < goal name > to display parameter details |
spring-boot:repackage | Repackage the existing JAR and WAR archives so that you can use java -jar Withlayout=NONE can also be simply used to package jars with nested dependencies (there is no main class, so it is not executable). |
spring-boot:run | Running applications in place |
spring-boot:start | Start a spring application. Contrary to the run target, this does not prevent and allow other targets to operate on the application. This target is usually used for integration test scenarios where the application starts before the test suite and stops after the test suite. |
spring-boot:stop | Stops the application initiated by the start target. It is usually called after the test suite is completed. |
5. Package executable
The plug-in can create an executable Archive (jar file and war file) containing all the dependencies of the application, and then use java -jar
The packaging executable archive is performed by the repackage target, as shown in the following example:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
If you are using spring boot starter parent, the repackage execution ID has been pre configured for such an execution, so you should only add the plug-in definition. |
The above example repackages a jar or war archive built during the packaging phase of the Maven lifecycle, including any dependencies defined in the provided project. If you need to exclude some of these dependencies, you can use one of the exclude options; for more details, see Dependency exclusion.
. original by default, the original (i.e. non executable) artifact is renamed to, but you can also use a custom classifier to keep the original artifact.
The function of outputFileNameMapping Maven war plugin is not supported at present. |
Devtools are automatically excluded by default (you can control it using the excludeDevtools property). In order for it to work with war packaging, spring boot devtools must set the dependency to the scope optional or with the provided scope.
The plug-in rewrites your list, especially it manages the main class and start class entries. If the default value does not work, you must configure the value in the Spring Boot plug-in, not in the jar plug-in. The properties of the spring guided plug-in in controlled by layout in the main class list are shown in the following example:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>${start.class}</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
The layout property defaults to the value determined by the archive type (jar or war). The following layouts can be used:
-
JAR: General executable JAR layout.
-
war: executable war layout. Provided places dependencies WEB-INF / lib provided to avoid any conflicts when war is deployed in the servlet container.
-
ZIP (alias DIR): similar to the layout properties launcher used by JAR.
-
NONE: bundle all dependencies and project resources. Do not bundle the boot loader.
5.1. Layered tank or war
The repackaged jars contain the application classes and dependencies BOOT-INF/lib in BOOT-INF/classes and. Similarly, the executable war includes the application classes WEB-INF/classes and dependencies WEB-INF/lib and WEB-INF/lib provided. For the case that the docker image needs to be built from the jar or war content, these directories can be further separated so that they can be written to Different layers can be useful.
Hierarchical archiving uses the same layout as a regular repackaged jar or war, but includes an additional metadata file to describe each layer.
By default, the following layers are defined:
-
dependencies does not contain SNAPSHOT. For any version
-
spring-boot-loader For loader classes.
-
SNAPSHOT dependencies includes SNAPSHOT. For any version
-
application Used for local module dependencies, application classes, and resources.
Identify module dependencies by looking at all modules that are part of the current build. If a module dependency can only be resolved because it is already installed in Maven's local cache and it is not part of the current build, it will be recognized as a regular dependency.
Layer order is important because it determines the possibility of caching previous layers when a part of the application changes. The default order is dependencies, spring-boot-loader, snapshot-dependencies, application. You should first add what is least likely to change, and then add layers that are more likely to change.
The repackaged archive layers.idx contains this file by default. To disable this feature, you can do so in the following ways:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layers> <enabled>false</enabled> </layers> </configuration> </plugin> </plugins> </build> </project>
[[packaging.layers.configuration =]] = = = customize layer configuration. Depending on your application, you may want to adjust the creation method of layers and add new layers. This can be done using a separate configuration file, which should be registered as follows:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layers> <enabled>true</enabled> <configuration>${project.basedir}/src/layers.xml</configuration> </layers> </configuration> </plugin> </plugins> </build> </project>
The configuration file describes how files are divided into layers and the order of these layers. The following example shows how to explicitly define the above default sort:
<layers xmlns="http://www.springframework.org/schema/boot/layers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/boot/layers https://www.springframework.org/schema/boot/layers/layers-2.5.xsd"> <application> <into layer="spring-boot-loader"> <include>org/springframework/boot/loader/**</include> </into> <into layer="application" /> </application> <dependencies> <into layer="application"> <includeModuleDependencies /> </into> <into layer="snapshot-dependencies"> <include>*:*:*SNAPSHOT</include> </into> <into layer="dependencies" /> </dependencies> <layerOrder> <layer>dependencies</layer> <layer>spring-boot-loader</layer> <layer>snapshot-dependencies</layer> <layer>application</layer> </layerOrder> </layers>
The layersXML format is described in three sections:
-
The < Application > block defines how application classes and resources should be layered.
-
The < dependencies > block defines how dependencies should be layered.
-
The < layerorder > block defines the order in which layers should be written.
Nested < into > blocks are used for internal < Application > and < dependencies > sections to declare the contents of the layer. These blocks are evaluated from top to bottom in the order they define. Anything not declared by the previous block can still be considered by subsequent blocks.
The < into > block declares content using nested < include > and < exclude > elements. The < Application > section uses Ant Style Patch matching for include / exclude expressions. This < dependencies > section uses the group:artifact[:version] mode. It also provides elements that can be used by < includemeduledependencies / > and < excludemoduledependences / > to include or exclude local module dependencies.
If no is defined in < include > , Then all content (not declared by an earlier block) is considered.
If no is defined in < exclude > , The exclusion is not applied.
Looking at the example above < dependencies >, we can see that the first < into > will declare application.layer The next < into > will declare all SNAPSHOT dependencies for this SNAPSHOT dependencies layer. Final < into > will declare anything left of the dependencies layer (in this case, any dependencies that are not SNAPSHOT).
The < Application > block has similar rules. First declare the org/springframework/boot/loader / * * content of the layer spring boot loader. Then declare any remaining classes and resources for the application layer.
< into > define block The order of is usually different from the order of writing layers. For this reason, the < layerorder > element must always be included and must cover all layers referenced by the < into > block. |
5.2. spring-boot:repackage
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Repackage the existing JAR and WAR archives so that you can use java -jar Withlayout=NONE can also be simply used to package jars with nested dependencies (there is no main class, so it is not executable).
5.2.1. Required parameters
full name | type | default |
---|---|---|
File | ${project.build.directory} |
5.2.2. Optional parameters
full name | type | default |
---|---|---|
boolean | true | |
String | ||
File | ||
Properties | ||
boolean | true | |
String | ||
List | ||
boolean | false | |
boolean | false | |
List | ||
String | ||
String | ${project.build.outputTimestamp} | |
List | ||
boolean | false |
5.2.3. Parameter details
attach
Attach a repackaged archive to be installed to a local Maven repository or deployed to a remote repository. If the classifier is not configured, it will replace the normal jar. If aclassifier is configured to be different from the normal jar and the repackaged jar, it will be attached with the normal jar. When this property is set to false, repackaged archives will not be installed or deployed.
full name | attach |
---|---|
type | boolean |
Default value | true |
user attribute | |
since | 1.4.0 |
classifier
Classifiers added to repackaged archives. If not, the main artifact will be replaced by a repackaged archive. If given, the classifier will also be used to determine the source archive to repackage: if the artifact with the classifier already exists, it will be used as the source and replaced. If there are no such artifacts, the main artifact will be used as the source and the repackaged archive will be attached as a supplementary artifact to the classifier. Additional artifacts allow them to be deployed with the original artifacts, see $1 [$2].
full name | classifier |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since | 1.0.0 |
embeddedLaunchScript
If the jar is fully executable, the embedded startup script should be placed in front of the jar. If not specified, the "Spring Boot" default script is used.
full name | embeddedLaunchScript |
---|---|
type | java.io.File |
Default value | |
user attribute | |
since | 1.3.0 |
embeddedLaunchScriptProperties
Properties that should be expanded in the embedded startup script.
full name | embeddedLaunchScriptProperties |
---|---|
type | java.util.Properties |
Default value | |
user attribute | |
since | 1.3.0 |
excludeDevtools
Exclude Spring Boot devtools from the repackaged archive.
full name | excludeDevtools |
---|---|
type | boolean |
Default value | true |
user attribute | spring-boot.repackage.excludeDevtools |
since | 1.3.0 |
excludeGroupIds
Comma separated list (exact match) of groupId names to exclude.
full name | excludeGroupIds |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.excludeGroupIds |
since | 1.1.0 |
excludes
The set of artifact definitions to Exclude. The Exclude element defines mandatory groupId and artifactId properties and optional classifier properties.
full name | excludes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.excludes |
since | 1.1.0 |
executable
Create a fully executable jar for the * nix machine by adding a startup script to the jar< p> At present, some tools do not accept this format, so you may not always be able to use this technology. For example, jar -xf may silently fail to extract a fully executable jar or war. It is recommended that you enable this option only when you intend to execute directly, rather than running it using the Java - jar servlet container or deploying it to the servlet container.
full name | executable |
---|---|
type | boolean |
Default value | false |
user attribute | |
since | 1.3.0 |
includeSystemScope
Include system wide dependencies.
full name | includeSystemScope |
---|---|
type | boolean |
Default value | false |
user attribute | |
since | 1.4.0 |
includes
A collection of artifact definitions to Include. The Include element defines mandatory groupId and artifactId attributes, optional mandatory groupId and artifactId attributes, and an optional classifier attribute.
full name | includes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.includes |
since | 1.2.0 |
layers
Layer configuration, including options to disable layer creation, exclude layer tool jar, and provide custom layer configuration files.
full name | layers |
---|---|
type | |
Default value | |
user attribute | |
since | 2.3.0 |
layout
The type of Archive (corresponding to how dependencies are laid out in it). Possible values are JAR, WAR, ZIP, DIR, NONE. The default is guess based on archive type.
full name | layout |
---|---|
type | org.springframework.boot.maven.AbstractPackagerMojo$LayoutType |
Default value | |
user attribute | spring-boot.repackage.layout |
since | 1.0.0 |
layoutFactory
If no explicit layout is set, it will be used to create a layout factory that can perform archiving. The 3rd party can provide alternative layout implementations.
full name | layoutFactory |
---|---|
type | |
Default value | |
user attribute | |
since | 1.5.0 |
mainClass
Name of the main class. If not specified, main uses the first compiled class found that contains the method.
full name | mainClass |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since | 1.0.0 |
outputDirectory
Directory containing the generated archive.
full name | outputDirectory |
---|---|
type | java.io.File |
Default value | ${project.build.directory} |
user attribute | |
since | 1.0.0 |
outputTimestamp
The timestamp of the reproducible output archive entry in the format ISO 8601( Yyyy mm dd'T'HH:mm:ssXXX) or int indicates the number of seconds since the era.
full name | outputTimestamp |
---|---|
type | java.lang.String |
Default value | ${project.build.outputTimestamp} |
user attribute | |
since | 2.3.0 |
requiresUnpack
List of libraries that must be unzipped from the fat can to run. Each specified library will be unzipped at run time as a < groupid > and < artifactid > of < dependency >.
full name | requiresUnpack |
---|---|
type | java.util.List |
Default value | |
user attribute | |
since | 1.1.0 |
skip
Skip execution.
full name | skip |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.repackage.skip |
since | 1.2.0 |
5.3. example
5.3.1. Custom classifier
By default, the repackage target replaces the original artifact with the repackaged artifact. This is sensible behavior for a module that represents an application, but if your module is used as a dependency on another module, you need to provide a classifier for the repackaged module. The reason for this is that the application classes are packaged, so the BOOT-INF/classes dependent module cannot load the repackaged jar classes.
If this is the case, or if you prefer to keep the original artifact and attach the repackaged artifact using a different classifier, configure the plug-in as follows:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
If you are using spring boot starter parent, the repackage target will automatically perform repackage in the execution with id. In this setting, only the configuration should be specified, as shown in the following example:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
This configuration generates two artifacts: the original artifact and the repackaging counterpart generated by the repackaging target. Both will be installed / deployed transparently.
You can also use the same configuration if you want to repackage the secondary artifact in the same way as replacing the primary artifact. The following configuration task s install / deploy a single classification artifact using a repackaged application:
<project> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <goals> <goal>jar</goal> </goals> <phase>package</phase> <configuration> <classifier>task</classifier> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>task</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Since the Maven jar plugin and the spring boot Maven plugin run in the same phase, it is important to define the jar plugin first (so that it runs before repackaging the target). Similarly, if you use spring boot starter parent, it can be simplified as follows:
<project> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <id>default-jar</id> <configuration> <classifier>task</classifier> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <configuration> <classifier>task</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
5.3.2. Custom name
If the jar you need to repackage has a local name whose artifact ID is different from the local name defined by the project property, use the standard finalName, as shown in the following example:
<project> <build> <finalName>my-app</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
This configuration will be in target / my app.jar
5.3.3. Locally repackaged workpieces
By default, the repackage target replaces the original artifact with an executable artifact. If you only need to deploy the original jar and can run your application with a regular file name, configure the plug-in as follows:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> <configuration> <attach>false</attach> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
This configuration generates two artifacts: the original artifact and the executable counter portion generated by the repackage target. Only the original will be installed / deployed.
5.3.4. custom layout
Spring Boot uses the custom layout factory defined in the attached jar file to repackage the jar file of this project as a dependency for building the plug-in:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> <configuration> <layoutFactory implementation="com.example.CustomLayoutFactory"> <customProperty>value</customProperty> </layoutFactory> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>custom-layout</artifactId> <version>0.0.1.BUILD-SNAPSHOT</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
Layout factory as LayoutFactory(from) Spring boot loader tools) is provided by the implementation explicitly specified in the pom.xml file. If there is only one customization on the LayoutFactory plug-in classpath and it is listed, META-INF/spring.factories, it is not necessary to explicitly set it in the plug-in configuration.
If explicit is set Layout, The layout factory is always ignored.
5.3.5. Dependency exclusion
By default, both the target repackage and run targets will contain any dependencies defined in the provided project. Spring Boot projects should treat the provided dependency as a "container" dependency needed to run the application.
Some of these dependencies may not be needed at all and should be excluded from the executable jar. For consistency, they should not appear when running the application.
There are two ways to exclude dependencies from packaging / usage at run time:
-
Exclude the artifactId of a specific artifact identified by groupId and. The classifier can choose to use it if necessary.
-
Exclude those belonging to the given groupId
The following example excludes com.example:module1 and excludes only this artifact:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>com.example</groupId> <artifactId>module1</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>
This example excludes any artifacts that belong to this com.example group:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludeGroupIds>com.example</excludeGroupIds> </configuration> </plugin> </plugins> </build> </project>
5.3.6. Tiered archiving tools
When you create a layered jar or war, the spring boot jarmode layertools jar is added to your archive as a dependency. Using this jar on the classpath, you can start your application in a special mode that allows boot code to run things completely different from your application, such as extracting layers. If you want to exclude this dependency, you can do so in the following ways:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layers> <includeLayerTools>false</includeLayerTools> </layers> </configuration> </plugin> </plugins> </build> </project>
5.3.7. Custom layer configuration
The default setting splits dependencies into snapshots and non snapshots, but you may have more complex rules. For example, you might want to isolate the company specific dependencies of a project in a dedicated layer. The following layers.xml configuration shows one such setting:
<layers xmlns="http://www.springframework.org/schema/boot/layers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/boot/layers https://www.springframework.org/schema/boot/layers/layers-2.5.xsd"> <application> <into layer="spring-boot-loader"> <include>org/springframework/boot/loader/**</include> </into> <into layer="application" /> </application> <dependencies> <into layer="snapshot-dependencies"> <include>*:*:*SNAPSHOT</include> </into> <into layer="company-dependencies"> <include>com.acme:*</include> </into> <into layer="dependencies"/> </dependencies> <layerOrder> <layer>dependencies</layer> <layer>spring-boot-loader</layer> <layer>snapshot-dependencies</layer> <layer>company-dependencies</layer> <layer>application</layer> </layerOrder> </layers>
The above configuration creates an additional company dependencies layer that contains all libraries with com.acmegroupId.
6. Package OCI image
The plug-in can use Cloud Native Buildpacks (CNB) create from jar or war file OCI image . You can use the target to build an image. build-image
For security reasons, images are built and run as non root users. For more details, see CNB specification. |
The easiest way to get started is to call MVN spring boot: build image a project. Images can be created automatically during the package call phase, as shown in the following example:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>build-image</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Although buildpack from Executable Archive Run, but it is not necessary to execute the repackage target first, because the executable archive is automatically created if necessary. When build image repackages an application, it applies the same settings as the repackage target, that is, you can use one of the exclusion options to exclude dependencies, and Devtools is automatically excluded by default (you can use the excludeDevtools property to control it). |
6.1. Docker daemon
The build image target needs to access the Docker daemon. By default, it will communicate with the Docker daemon through a local connection. This applies to all supported platforms Docker engine , no configuration required.
You can set environment variables to configure the build image target to use Provided by minicube of Docker daemon . The following table shows the environment variables and their values:
environment variable | describe |
---|---|
DOCKER_HOST | URL of the host and port containing the Docker daemon - for example tcp://192.168.99.100:2376 |
DOCKER_TLS_VERIFY | Enable secure HTTPS protocol when set to 1 (optional) |
DOCKER_CERT_PATH | Path to HTTPS certificate and key file (if required, dock_tls_verify = 1, otherwise ignored) |
On Linux and Mac OS, you can set these environment variables with the command Eval $(minicube docker Env) after minicube starts.
The connection information of the docker daemon can also be provided using the parameters in the docker plug-in configuration. The following table summarizes the available parameters:
Range | describe |
---|---|
host | URL of the host and port containing the Docker daemon - for example tcp://192.168.99.100:2376 |
tlsVerify | Enable secure HTTPS protocol when set to true (optional) |
certPath | Path to certificate and key files for HTTPS (required if tlsVerify is true, ignored otherwise) |
For more details, see also examples.
6.2. Docker Registry
If the Docker images specified by the builder or runImage parameters are stored in a private Docker image registry that requires authentication, the authentication credentials can be provided using docker.builderRegistry parameters.
If the generated Docker image is to be published to a Docker image registry, the authentication credentials can be provided using docker.publishRegistry parameters.
Parameters are provided for user authentication or identity token authentication. Consult the documentation for the Docker registry being used to store images for further information on supported authentication methods.
The following table summarizes the available parameters for docker.builderRegistry and docker.publishRegistry:
Parameter | Description |
---|---|
username | Username for the Docker image registry user. Required for user authentication. |
password | Password for the Docker image registry user. Required for user authentication. |
url | Address of the Docker image registry. Optional for user authentication. |
| E-mail address for the Docker image registry user. Optional for user authentication. |
token | Identity token for the Docker image registry user. Required for token authentication. |
For more details, see also examples.
6.3. Image Customizations
The plug-in calls Builder To coordinate the generation of images. The washing aid comprises a plurality of buildpacks You can check the application to affect the resulting image. By default, the plug-in selects the builder image. The name of the generated image is derived from the project properties.
This image parameter allows you to configure the builder and how it should run on the project. The following table summarizes the available parameters and their default values:
Parameters / (user properties) | describe | Default value |
---|---|---|
builder | The name of the builder image to use. | paketobuildpacks/builder:base |
runImage | The name of the running image to use. | No default value indicates that the run image specified in the Builder metadata should be used. |
name | Of the generated image Image name. | docker.io/library/ |
pullPolicy | strategy Used to determine when to pull builders and run images from the registry. Acceptable values are ALWAYS, NEVER, and IF_NOT_PRESENT. | ALWAYS |
env | Environment variables that should be passed to the builder. | |
buildpacks |
The build package that the builder should use when building the image. Only the specified build package is used, overriding the default build package contained in the builder. The Buildpack reference must take one of the following forms:
| None indicates that the builder should use the build package contained therein. |
bindings |
The container that should be installed into the builder when building the image Volume binding installation . When the builder container is created, the binding is passed to Docker without resolution and validation. Binding must take one of the following forms:
Where < Options > can contain:
| |
cleanCache | Whether to clean up the cache before building. | false |
verboseLogging | Enables detailed logging of builder operations. | false |
publish | Whether to publish the generated image to the Docker registry. | false |
The plug-in uses the compiler's plug-in configuration or the maven.compiler.target attribute to detect the target Java compatibility of the project. When using the default Paketo builder and build package, the plug-in instructs the build package to install the same java version. You can override this behavior, such as Builder configuration Shown in the example. |
For more details, see also Example.
6.4. spring-boot:build-image
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Use buildpack to package the application into an OCI image.
6.4.1. Required parameters
full name | type | default |
---|---|---|
File | ${project.build.directory} |
6.4.2. Optional parameters
full name | type | default |
---|---|---|
String | ||
boolean | true | |
String | ||
List | ||
boolean | false | |
List | ||
String | ||
boolean | false |
6.4.3. Parameter details
classifier
The classifier used to find the source archive.
full name | classifier |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since | 2.3.0 |
docker
Docker configuration options.
full name | docker |
---|---|
type | |
Default value | |
user attribute | |
since | 2.4.0 |
excludeDevtools
Exclude Spring Boot devtools from the repackaged archive.
full name | excludeDevtools |
---|---|
type | boolean |
Default value | true |
user attribute | spring-boot.repackage.excludeDevtools |
since | 1.3.0 |
excludeGroupIds
Comma separated list (exact match) of groupId names to exclude.
full name | excludeGroupIds |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.excludeGroupIds |
since | 1.1.0 |
excludes
The set of artifact definitions to Exclude. The Exclude element defines mandatory groupId and artifactId properties and optional classifier properties.
full name | excludes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.excludes |
since | 1.1.0 |
image
Image configuration, with builder, runImage, name, env, cleanCache, verboseLogging, pullPolicy, and publish options.
full name | image |
---|---|
type | |
Default value | |
user attribute | |
since | 2.3.0 |
includeSystemScope
Include system wide dependencies.
full name | includeSystemScope |
---|---|
type | boolean |
Default value | false |
user attribute | |
since | 1.4.0 |
includes
A collection of artifact definitions to Include. The Include element defines mandatory groupId and artifactId attributes, optional mandatory groupId and artifactId attributes, and an optional classifier attribute.
full name | includes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.includes |
since | 1.2.0 |
layers
Layer configuration, including options to disable layer creation, exclude layer tool jar, and provide custom layer configuration files.
full name | layers |
---|---|
type | |
Default value | |
user attribute | |
since | 2.3.0 |
layout
The type of Archive (corresponding to how dependencies are laid out in it). Possible values are JAR, WAR, ZIP, DIR, NONE. The default is guess based on archive type.
full name | layout |
---|---|
type | org.springframework.boot.maven.AbstractPackagerMojo$LayoutType |
Default value | |
user attribute | |
since | 2.3.11 |
layoutFactory
If no explicit layout is set, it will be used to create a layout factory that can perform archiving. The 3rd party can provide alternative layout implementations.
full name | layoutFactory |
---|---|
type | |
Default value | |
user attribute | |
since | 2.3.11 |
mainClass
Name of the main class. If not specified, main uses the first compiled class found that contains the method.
full name | mainClass |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since | 1.0.0 |
skip
Skip execution.
full name | skip |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.build-image.skip |
since | 2.3.0 |
sourceDirectory
Directory containing the source archive.
full name | sourceDirectory |
---|---|
type | java.io.File |
Default value | ${project.build.directory} |
user attribute | |
since | 2.3.0 |
6.5. example
6.5.1. Custom image generator
If you need to customize the builder used to create an image or the running image used to start building an image, configure the plug-in as follows:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <builder>mine/java-cnb-builder</builder> <runImage>mine/java-cnb-run</runImage> </image> </configuration> </plugin> </plugins> </build> </project>
The configuration will use a builder image name mine / Java CNB builder and the tag latest, and will name the concatenated image mine / Java CNB run and the tag latest.
The builder and running image can also be specified on the command line, as shown in the following example:
$ mvn spring-boot:build-image -Dspring-boot.build-image.builder=mine/java-cnb-builder -Dspring-boot.build-image.runImage=mine/java-cnb-run
6.5.2. Builder configuration
If the builder exposes configuration options using environment variables, you can set them using the env property.
Here's what happens when you build to configure Using Paketo Java buildpacks JVM version of Examples of:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <env> <BP_JVM_VERSION>8.*</BP_JVM_VERSION> </env> </image> </configuration> </plugin> </plugins> </build> </project>
If there is a network agent between the Docker daemon where the builder runs and the network location from which the build package downloads artifacts, you need to configure the builder to use the agent. When using the Paketo builder, this can be done by setting HTTPS_PROXY and / or HTTP_PROXY environment variable, as shown in the following example:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <env> <HTTP_PROXY>http://proxy.example.com</HTTP_PROXY> <HTTPS_PROXY>https://proxy.example.com</HTTPS_PROXY> </env> </image> </configuration> </plugin> </plugins> </build> </project>
6.5.3. Runtime JVM configuration
The Paketo Java build package sets environment variables to Configuring the JVM runtime environment JAVA_TOOL_OPTIONS. JAVA_TOOL_OPTIONS when the application image starts in the container, you can modify the value provided by buildpack to customize the JVM runtime behavior.
The environment variables that should be stored in the image and applied to each deployment can be modified as follows In Paketo document The description is set and displayed in the following example:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <env> <BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS> <BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:+HeapDumpOnOutOfMemoryError</BPE_APPEND_JAVA_TOOL_OPTIONS> </env> </image> </configuration> </plugin> </plugins> </build> </project>
6.5.4. Custom image name
By default, the image name is inferred from the artifact ID and version of the project, similar to docker. IO / library / ${project. Artifact ID}: ${project. Version} You can control the name, as shown in the following example:
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <name>example.com/library/${project.artifactId}</name> </image> </configuration> </plugin> </plugins> </build> </project>
You can also specify the image name on the command line, as shown in the following example:
$ mvn spring-boot:build-image -Dspring-boot.build-image.imageName=example.com/library/my-app:v1
6.5.5. Build package
By default, the builder uses the build packages contained in the builder image and applies them in a predefined order. You can provide a set of alternative build packages to apply build packages that are not included in the builder, or change the order of included build packages. When one or more buildpacks are provided, only the specified buildpacks are applied.
The following example instructs the builder to use a custom build package packaged in a. tgz file, followed by the build package included in the builder.
<project> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <buildpacks> <buildpack>file:///path/to/example-buildpack.tgz</buildpack> <buildpack>urn:cnb:builder:paketo-buildpacks/java</buildpack> </buildpacks> </image> </configuration> </plugin> </plugins> </build> </project>
Buildpacks can be specified in any of the forms shown below.
Build package located in CNB Builder (if there is only one build package matching with in the builder, the version buildpack ID can be omitted):
-
urn:cnb:builder:buildpack-id
-
urn:cnb:builder:buildpack-id@0.0.1
-
buildpack-id
-
buildpack-id@0.0.1
Path to directory containing buildpack content (not supported by Windows):
-
file:///path/to/buildpack/
-
/path/to/buildpack/
Path to gzip tar file containing buildpack content:
-
file:///path/to/buildpack.tgz
-
/path/to/buildpack.tgz
contain Package buildpack OCI image for:
-
docker://example/buildpack
-
docker:///example/buildpack:latest
-
docker:///example/buildpack@sha256:45b23dee08...
-
example/buildpack
-
example/buildpack:latest
-
example/buildpack@sha256:45b23dee08...
6.5.6. Picture Publishing
The generated image can be published to the Docker registry by enabling the publish option and configuring the authentication of the registry with the docker.publishRegistry parameter.
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">image</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">name</span>></span>docker.example.com/library/${project.artifactId}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">name</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">publish</span>></span>true<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">publish</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">image</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">publishRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">username</span>></span>user<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">username</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">password</span>></span>secret<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">password</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">url</span>></span>https://docker.example.com/v1/<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">url</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">email</span>></span>user@example.com<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">email</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">publishRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
The publish option can be specified on the command line as well, as shown in this example:
$ mvn spring-boot:build-image -Dspring-boot.build-image.imageName=docker.example.com/library/my-app:v1 -Dspring-boot.build-image.publish=true
6.5.7. Docker Configuration
If you need the plugin to communicate with the Docker daemon using a remote connection instead of the default local connection, the connection details can be provided using docker parameters as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">host</span>></span>tcp://192.168.99.100:2376<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">host</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">tlsVerify</span>></span>true<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">tlsVerify</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">certPath</span>></span>/home/user/.minikube/certs<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">certPath</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
If the builder or running image is stored in a private Docker registry that supports user authentication, you can use the docker.builderRegistry parameter to provide authentication details, as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">builderRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">username</span>></span>user<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">username</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">password</span>></span>secret<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">password</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">url</span>></span>https://docker.example.com/v1/<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">url</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">email</span>></span>user@example.com<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">email</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">builderRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
If the builder or running image is stored in a private Docker registry that supports token authentication, you can use the docker.builderRegistry parameter to provide the token value, as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">builderRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">token</span>></span>9cbaf023786cd7...<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">token</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">builderRegistry</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">docker</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
7. Run your application using Maven
The plug-in contains a running target that can be used to launch your application from the command line, as shown in the following example:
$ mvn spring-boot:run
You can use the arguments parameter to specify Application parameters, For more details, see Use application parameters.
By default, the application executes in a forked process, and setting properties on the command line does not affect the application. If you need to specify some JVM parameters (that is, for debugging purposes), you can use the jvmArguments parameter. For more details, see Debug application . Also explicitly support System properties and environment variable.
Since enabling configuration files is very common, there is a special profile attribute to provide shortcuts to - Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev", see Specify activity profile.
Although this is not recommended, you can execute the application directly from the Maven JVM by disabling the fork attribute. This means that the jvmArguments, systemPropertyVariables, environmentVariables, and agents options are ignored.
Spring Bootdevtools is a module for improving the experience of Spring Boot application development. To enable it, simply add the following dependencies to your project:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">dependencies</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">dependency</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-devtools<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">optional</span>></span>true<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">optional</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">dependency</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">dependencies</span>></span></code></span></span>
When devtools runs, it detects changes when you recompile the application and refresh it automatically. This applies not only to resources, but also to code. It also provides a LiveReload server to automatically trigger browser refresh when the situation changes.
Devtools can also be configured to refresh the browser only when static resources change (and ignore any changes in the code). Just include the following properties in your project:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-properties"><span style="color:var(--highlight-meta-font-color)">spring.devtools.remote.restart.enabled</span>=<span style="color:var(--highlight-string-font-color)">false</span></code></span></span>
Before devtools, the plug-in supported hot refresh resources by default. Now it has been disabled to support the above solution. You can restore it at any time by configuring items:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">addResources</span>></span>true<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">addResources</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span></code></span></span>
When addResources is enabled, any src/main/resources when you run the application and any duplicate found directory will be added to the application class path, and target/classes will be deleted. This allows hot refresh of resources, which is useful when developing Web applications. For example, you can work with HTML, CSS, or JavaScript files and see your changes immediately without recompiling your application. It is also a useful way to allow front-end developers to work without downloading and installing the Java IDE.
One side effect of using this feature is that filtering resources at build time will not work. |
To be consistent with the repackage target, the target run builds the classpath in such a way that any dependencies excluded from the plug-in configuration are also excluded from the classpath. For more details, see Dedicated example.
Sometimes it is useful to include test dependencies when running an application. For example, if you want to run your application in test mode using stub classes. If you want to do this, you can set the useTestClasspath parameter to true.
This applies only when you run the application: the repackage target does not add test dependencies to the generated JAR/WAR. |
7.1. spring-boot:run
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Run the application in place.
7.1.1. Required parameters
full name | type | default |
---|---|---|
File | ${project.build.outputDirectory} |
7.1.2. Optional parameters
full name | type | default |
---|---|---|
boolean | false | |
File[] | ||
String[] | ||
String | ||
String[] | ||
Map | ||
String | ||
List | ||
boolean | true | |
List | ||
String | ||
String | ||
boolean | ||
boolean | true | |
String[] | ||
boolean | false | |
Map | ||
Boolean | false | |
File |
7.1.3. Parameter details
addResources
Add Maven resources directly to the classpath, which allows real-time in place editing of resources. target/classes if ClassLoader.getResources() is called, duplicate resources will be deleted to prevent them from appearing twice. Consider adding spring boot devtools to your project because it provides this and more.
full name | addResources |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.run.addResources |
since | 1.0.0 |
agents
The path to the proxy jar. Note: using this function requires a forked process.
full name | agents |
---|---|
type | java.io.File[] |
Default value | |
user attribute | spring-boot.run.agents |
since | 2.2.0 |
arguments
Parameters that should be passed to the application.
full name | arguments |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | |
since | 1.0.0 |
classesDirectory
A directory containing class and resource files that should be packaged into the archive.
full name | classesDirectory |
---|---|
type | java.io.File |
Default value | ${project.build.outputDirectory} |
user attribute | |
since | 1.0.0 |
commandlineArguments
Parameters that should be passed to the application on the command line. Separate multiple parameters with spaces and ensure that multiple values are included between quotation marks. When specified, takes precedence over #arguments.
full name | commandlineArguments |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.arguments |
since | 2.2.3 |
directories
Directories other than the class directory that should be added to the classpath.
full name | directories |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | spring-boot.run.directories |
since | 1.0.0 |
environmentVariables
A list of environment variables that should be associated with the forked process used to run the application. Note: using this function requires a forked process.
full name | environmentVariables |
---|---|
type | java.util.Map |
Default value | |
user attribute | |
since | 2.1.0 |
excludeGroupIds
Comma separated list (exact match) of groupId names to exclude.
full name | excludeGroupIds |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.excludeGroupIds |
since | 1.1.0 |
excludes
The set of artifact definitions to Exclude. The Exclude element defines mandatory groupId and artifactId properties and optional classifier properties.
full name | excludes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.excludes |
since | 1.1.0 |
fork
Flag indicating whether processes should be forked. Disabling forking disables certain features, such as agents, custom JVM parameters, development tools, or specifying the working directory to use.
full name | fork |
---|---|
type | boolean |
Default value | true |
user attribute | spring-boot.run.fork |
since | 1.2.0 |
includes
A collection of artifact definitions to Include. The Include element defines mandatory groupId and artifactId attributes, optional mandatory groupId and artifactId attributes, and an optional classifier attribute.
full name | includes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.includes |
since | 1.2.0 |
jvmArguments
JVM parameters that should be associated with the forked process used to run the application. On the command line, make sure you include multiple values between quotation marks. Note: using this function requires a forked process.
full name | jvmArguments |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.jvmArguments |
since | 1.1.0 |
mainClass
Name of the main class. If not specified, the first compiled class found that contains the "main" method is used.
full name | mainClass |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.main-class |
since | 1.0.0 |
noverify
The tag indicates that the agent requires - noverify.
full name | noverify |
---|---|
type | boolean |
Default value | |
user attribute | spring-boot.run.noverify |
since | 1.0.0 |
optimizedLaunch
Whether JVM startup should be optimized.
full name | optimizedLaunch |
---|---|
type | boolean |
Default value | true |
user attribute | spring-boot.run.optimizedLaunch |
since | 2.2.0 |
profiles
The spring profile to activate. Specify a shortcut to the 'spring.profiles.active' parameter. Use commas to separate multiple configuration files on the command line.
full name | profiles |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | spring-boot.run.profiles |
since | 1.3.0 |
skip
Skip execution.
full name | skip |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.run.skip |
since | 1.3.2 |
systemPropertyVariables
List of JVM system properties to pass to the process. Note: using this function requires a forked process.
full name | systemPropertyVariables |
---|---|
type | java.util.Map |
Default value | |
user attribute | |
since | 2.1.0 |
useTestClasspath
Tag to include the test classpath at run time.
full name | useTestClasspath |
---|---|
type | java.lang.Boolean |
Default value | false |
user attribute | spring-boot.run.useTestClasspath |
since | 1.3.0 |
workingDirectory
The current working directory for the application. If not specified, basedir is used. Note: using this function requires a forked process.
full name | workingDirectory |
---|---|
type | java.io.File |
Default value | |
user attribute | spring-boot.run.workingDirectory |
since | 1.5.0 |
7.2. example
7.2.1. Debug application
By default, the run target runs your application in a forked process. If you need to debug it, you should add the necessary JVM parameters to enable remote debugging. The following configuration pauses the process until the debugger joins port 5005:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">jvmArguments</span>></span> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">jvmArguments</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
These parameters can also be specified on the command line to ensure correct packaging, that is:
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
7.2.2. Use system properties
You can use the systemPropertyVariables property to specify system properties. The following example sets property1 to test and property242:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">properties</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">my.value</span>></span>42<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">my.value</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">properties</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">systemPropertyVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">property1</span>></span>test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">property1</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">property2</span>></span>${my.value}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">property2</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">systemPropertyVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
If the value is empty or not defined (i.e. <my-property/>), the system property is set with an empty String as the value. Maven trims values specified in the pom so it is not possible to specify a System property which needs to start or end with a space via this mechanism: consider using jvmArguments instead.
Any String typed Maven variable can be passed as system properties. Any attempt to pass any other Maven variable type (e.g. a List or a URL variable) will cause the variable expression to be passed literally (unevaluated).
The jvmArguments parameter takes precedence over system properties defined with the mechanism above. In the following example, the value for property1 is overridden:
$ mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dproperty1=overridden"
7.2.3. Using Environment Variables
Environment variables can be specified using the environmentVariables attribute. The following example sets the 'ENV1', 'ENV2', 'ENV3', 'ENV4' env variables:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">environmentVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">ENV1</span>></span>5000<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">ENV1</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">ENV2</span>></span>Some Text<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">ENV2</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">ENV3</span>/></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">ENV4</span>></span><span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">ENV4</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">environmentVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
If the value is empty or not defined (i.e. <MY_ENV/>), the env variable is set with an empty String as the value. Maven trims values specified in the pom so it is not possible to specify an env variable which needs to start or end with a space.
Any String typed Maven variable can be passed as system properties. Any attempt to pass any other Maven variable type (e.g. a List or a URL variable) will cause the variable expression to be passed literally (unevaluated).
Environment variables defined this way take precedence over existing values.
7.2.4. Using Application Arguments
You can use the arguments property to specify application parameters. The following example sets two parameters: property1 and property2=42:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">arguments</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">argument</span>></span>property1<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">argument</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">argument</span>></span>property2=${my.value}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">argument</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">arguments</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
On the command line, arguments are separated by spaces in the same way. If the parameter contains spaces, be sure to reference it. In the following example, two parameters are available: property1 and property2=Hello World:
$ mvn spring-boot:run -Dspring-boot.run.arguments="property1 'property2=Hello World'"
7.2.5. Specify activity profile
You can use the profiles parameter to specify the active profile for a particular application.
The following configuration enables the local and dev configuration files:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">profiles</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">profile</span>></span>local<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">profile</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">profile</span>></span>dev<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">profile</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">profiles</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
The configuration files to be enabled can also be specified on the command line, making sure they are separated by commas, as shown in the following example:
$ mvn spring-boot:run -Dspring-boot.run.profiles=local,dev
8. Run integration test
Although you can easily launch your Spring Boot application from your test (or test suite) itself, it may be desirable to deal with it in the build itself. To ensure that the Spring Boot application lifecycle is properly managed around integration testing, you can use start and stop targets, as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>pre-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>start<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>post-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>stop<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span></code></span></span>
Such a setting is now available Fail safe plug-in To run the integration tests you expect.
By default, the application starts in a separate process and communicates with the application using JMX. If you need to configure JMX ports, see Dedicated example. |
You can also configure more advanced settings to skip integration testing after setting specific properties, see Dedicated example.
8.1. Using fail safe without the parent POM of Spring Boot
The parent pomspring boot starter parent of Spring Boot configures fail safe < classesdirectory > to ${project.build.outputDirectory} Without this configuration, it will cause Failsafe to use compiled classes instead of repackaged jar s, and Failsafe cannot load application classes. If you do not use the parent POM, you should configure Failsafe in the same way, as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.apache.maven.plugins<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>maven-failsafe-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">classesDirectory</span>></span>${project.build.outputDirectory}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">classesDirectory</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span></code></span></span>
8.2. spring-boot:start
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Start a spring application. In contrast to the run target, this does not prevent and allow other targets to operate on the application. This goal is typically used in integration test scenarios where the application starts before the test suite and stops after the test suite.
8.2.1. Required parameters
full name | type | default |
---|---|---|
File | ${project.build.outputDirectory} |
8.2.2. Optional parameters
full name | type | default |
---|---|---|
boolean | false | |
File[] | ||
String[] | ||
String | ||
String[] | ||
Map | ||
String | ||
List | ||
boolean | true | |
List | ||
String | ||
int | ||
String | ||
String | ||
int | ||
boolean | ||
String[] | ||
boolean | false | |
Map | ||
Boolean | false | |
long | ||
File |
8.2.3. Parameter details
addResources
Add Maven resources directly to the classpath, which allows real-time in place editing of resources. target/classes if ClassLoader.getResources() is called, duplicate resources will be deleted to prevent them from appearing twice. Consider adding spring boot devtools to your project because it provides this and more.
full name | addResources |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.run.addResources |
since | 1.0.0 |
agents
The path to the proxy jar. Note: using this function requires a forked process.
full name | agents |
---|---|
type | java.io.File[] |
Default value | |
user attribute | spring-boot.run.agents |
since | 2.2.0 |
arguments
Parameters that should be passed to the application.
full name | arguments |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | |
since | 1.0.0 |
classesDirectory
A directory containing class and resource files that should be packaged into the archive.
full name | classesDirectory |
---|---|
type | java.io.File |
Default value | ${project.build.outputDirectory} |
user attribute | |
since | 1.0.0 |
commandlineArguments
Parameters that should be passed to the application on the command line. Separate multiple parameters with spaces and ensure that multiple values are included between quotation marks. When specified, takes precedence over #arguments.
full name | commandlineArguments |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.arguments |
since | 2.2.3 |
directories
Directories other than the class directory that should be added to the classpath.
full name | directories |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | spring-boot.run.directories |
since | 1.0.0 |
environmentVariables
A list of environment variables that should be associated with the forked process used to run the application. Note: using this function requires a forked process.
full name | environmentVariables |
---|---|
type | java.util.Map |
Default value | |
user attribute | |
since | 2.1.0 |
excludeGroupIds
Comma separated list (exact match) of groupId names to exclude.
full name | excludeGroupIds |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.excludeGroupIds |
since | 1.1.0 |
excludes
The set of artifact definitions to Exclude. The Exclude element defines mandatory groupId and artifactId properties and optional classifier properties.
full name | excludes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.excludes |
since | 1.1.0 |
fork
Flag indicating whether processes should be forked. Disabling forking disables certain features, such as agents, custom JVM parameters, development tools, or specifying the working directory to use.
full name | fork |
---|---|
type | boolean |
Default value | true |
user attribute | spring-boot.run.fork |
since | 1.2.0 |
includes
A collection of artifact definitions to Include. The Include element defines mandatory groupId and artifactId attributes, optional mandatory groupId and artifactId attributes, and an optional classifier attribute.
full name | includes |
---|---|
type | java.util.List |
Default value | |
user attribute | spring-boot.includes |
since | 1.2.0 |
jmxName
JMX name of the automatically deployed MBean that manages the spring application lifecycle.
full name | jmxName |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since |
jmxPort
If the application is forked, the port used to expose the platform MBeanServer.
full name | jmxPort |
---|---|
type | int |
Default value | |
user attribute | |
since |
jvmArguments
JVM parameters that should be associated with the forked process used to run the application. On the command line, make sure you include multiple values between quotation marks. Note: using this function requires a forked process.
full name | jvmArguments |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.jvmArguments |
since | 1.1.0 |
mainClass
Name of the main class. If not specified, the first compiled class found that contains the "main" method is used.
full name | mainClass |
---|---|
type | java.lang.String |
Default value | |
user attribute | spring-boot.run.main-class |
since | 1.0.0 |
maxAttempts
The maximum number of attempts to check whether the spring application is ready. Combined with the "wait" parameter, this gives a global timeout value (30 seconds by default)
full name | maxAttempts |
---|---|
type | int |
Default value | |
user attribute | |
since |
noverify
The tag indicates that the agent requires - noverify.
full name | noverify |
---|---|
type | boolean |
Default value | |
user attribute | spring-boot.run.noverify |
since | 1.0.0 |
profiles
The spring profile to activate. Specify a shortcut to the 'spring.profiles.active' parameter. Use commas to separate multiple configuration files on the command line.
full name | profiles |
---|---|
type | java.lang.String[] |
Default value | |
user attribute | spring-boot.run.profiles |
since | 1.3.0 |
skip
Skip execution.
full name | skip |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.run.skip |
since | 1.3.2 |
systemPropertyVariables
List of JVM system properties to pass to the process. Note: using this function requires a forked process.
full name | systemPropertyVariables |
---|---|
type | java.util.Map |
Default value | |
user attribute | |
since | 2.1.0 |
useTestClasspath
Tag to include the test classpath at run time.
full name | useTestClasspath |
---|---|
type | java.lang.Boolean |
Default value | false |
user attribute | spring-boot.run.useTestClasspath |
since | 1.3.0 |
wait
The number of milliseconds to wait between each attempt to check whether the spring application is ready.
full name | wait |
---|---|
type | long |
Default value | |
user attribute | |
since |
workingDirectory
The current working directory for the application. If not specified, basedir is used. Note: using this function requires a forked process.
full name | workingDirectory |
---|---|
type | java.io.File |
Default value | |
user attribute | spring-boot.run.workingDirectory |
since | 1.5.0 |
8.3. spring-boot:stop
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Stop the application started by the start target. It is usually called after the test suite is completed.
8.3.1. Optional parameters
full name | type | default |
---|---|---|
Boolean | ||
String | ||
int | ||
boolean | false |
8.3.2. Parameter details
fork
Flag indicating whether the process to stop has forked. By default, this value is inherited from and MavenProject has a default fork value( true). If set, it must match the value used by the StartMojo start process.
full name | fork |
---|---|
type | java.lang.Boolean |
Default value | |
user attribute | spring-boot.stop.fork |
since | 1.3.0 |
jmxName
JMX name of the automatically deployed MBean that manages the application lifecycle.
full name | jmxName |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since |
jmxPort
If the application is forked, the port used to find the platform MBeanServer.
full name | jmxPort |
---|---|
type | int |
Default value | |
user attribute | |
since |
skip
Skip execution.
full name | skip |
---|---|
type | boolean |
Default value | false |
user attribute | spring-boot.stop.skip |
since | 1.3.2 |
8.4. example
8.4.1. Random port for integration test
A good feature of Spring Boot test integration is that it can assign a free port to Web applications. When start uses the target of the plug-in, it is difficult to pass the actual port to the integration test itself by starting the Spring Boot application alone.
The following example shows how to use Build Helper Maven Plugin Achieve the same function:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.codehaus.mojo<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>build-helper-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>reserve-tomcat-port<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>reserve-network-port<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">phase</span>></span>process-resources<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">phase</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">portNames</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">portName</span>></span>tomcat.http.port<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">portName</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">portNames</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>pre-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>start<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">arguments</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">argument</span>></span>--server.port=${tomcat.http.port}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">argument</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">arguments</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>post-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>stop<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.apache.maven.plugins<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>maven-failsafe-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">systemPropertyVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">test.server.port</span>></span>${tomcat.http.port}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">test.server.port</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">systemPropertyVariables</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span></code></span></span>
You can now retrieve system properties from test.server.port in any integration test to create URL server specific properties.
8.4.2. Custom JMX port
This jmxPort property allows you to customize the port that the plug-in uses to communicate with Spring Boot applications.
This example shows how to customize a port when the port is already used by 9001:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">jmxPort</span>></span>9009<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">jmxPort</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>pre-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>start<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>post-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>stop<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span></code></span></span>
If you need to configure JMX ports, make sure to configure them in the global configuration shown above so that the two targets share. |
8.4.3. Skip integration test
This skip attribute allows you to completely skip the execution of the Spring Boot maven plug-in.
This example shows how to skip integration testing using command line properties and still ensure that the repackage target runs:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">properties</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">skip.it</span>></span>false<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">skip.it</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">properties</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>pre-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>start<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">skip</span>></span>${skip.it}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">skip</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">id</span>></span>post-integration-test<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">id</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>stop<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">skip</span>></span>${skip.it}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">skip</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.apache.maven.plugins<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>maven-failsafe-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">skip</span>></span>${skip.it}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">skip</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
By default, integration tests run, but this setting allows you to easily disable them on the command line, as follows:
$ mvn verify -Dskip.it=true
9. Integration with actuator
If the META-INF/build-info.properties file exists, Spring Boot Actuator displays build related information. The build info target generates files such as coordinates and construction time of the project. It also allows you to add any number of additional attributes, as shown in the following example:
<span style="color:#191e1e"><span style="background-color:#ffffff"><code class="language-xml"><span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">project</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">modelVersion</span>></span>4.0.0<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">modelVersion</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>build-info<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">groupId</span>></span>org.springframework.boot<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">groupId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span>spring-boot-maven-plugin<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">artifactId</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">goal</span>></span>build-info<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goal</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">goals</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">additionalProperties</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">encoding.source</span>></span>UTF-8<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">encoding.source</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">encoding.reporting</span>></span>UTF-8<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">encoding.reporting</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">java.source</span>></span>${maven.compiler.source}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">java.source</span>></span> <span style="color:var(--highlight-tag-font-color)"><<span style="color:var(--highlight-tag-font-color)">java.target</span>></span>${maven.compiler.target}<span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">java.target</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">additionalProperties</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">configuration</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">execution</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">executions</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugin</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">plugins</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">build</span>></span> <span style="color:var(--highlight-tag-font-color)"></<span style="color:var(--highlight-tag-font-color)">project</span>></span></code></span></span>
This configuration will generate build-info.properties with four additional keys where expected.
maven.compiler.source and maven.compiler.target are expected to be general properties available in the project. They will interpolate as you expect. |
9.1. spring-boot:build-info
org.springframework.boot:spring-boot-maven-plugin:2.5.6
build-info.properties generates the MavenProject file based on the current content.
9.1.1. Optional parameters
full name | type | default |
---|---|---|
Map | ||
File | ${project.build.outputDirectory}/META-INF/build-info.properties | |
String |
9.1.2. Parameter details
additionalProperties
Other properties to be stored in the build-info.properties file. Each entry is in the generated build-info.properties
full name | additionalProperties |
---|---|
type | java.util.Map |
Default value | |
user attribute | |
since |
outputFile
The location where the build-info.properties file was generated.
full name | outputFile |
---|---|
type | java.io.File |
Default value | ${project.build.outputDirectory}/META-INF/build-info.properties |
user attribute | |
since |
time
Build.time is used for the property's value Instant#parse(CharSequence) in a suitable form. The default is session.request.startTime To disable this property completely in build.time, use 'off'
full name | time |
---|---|
type | java.lang.String |
Default value | |
user attribute | |
since | 2.2.0 |
10. Help information
The help target is a standard, and its purpose is to display the functional information of the plug-in.
10.1. spring-boot:help
org.springframework.boot:spring-boot-maven-plugin:2.5.6
Displays help on the spring boot Maven plugin. Call MVN spring boot: Help - ddetail = true - dgoal = < goal name > to display parameter details.
10.1.1. Optional parameters
full name | type | default |
---|---|---|
boolean | false | |
String | ||
int | 2 | |
int | 80 |
10.1.2. Parameter details
detail
If true, all settable properties for each target are displayed.
full name | detail |
---|---|
type | boolean |
Default value | false |
user attribute | detail |
since |
goal
Displays the name of the target for help. If not specified, all targets are displayed.
full name | goal |
---|---|
type | java.lang.String |
Default value | |
user attribute | goal |
since |
indentSize
The number of spaces per indentation level should be positive.
full name | indentSize |
---|---|
type | int |
Default value | 2 |
user attribute | indentSize |
since |
lineLength
The maximum length of the display line should be positive.
full name | lineLength |
---|---|
type | int |
Default value | 80 |
user attribute | lineLength |
since |