Skip to content

Extract XML examples from Maven plugin adoc files #25534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,9 @@ Spring Boot Actuator displays build-related information if a `META-INF/build-inf
The `build-info` goal generates such file with the coordinates of the project and the build time.
It also allows you to add an arbitrary number of additional properties, as shown in the following example:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>UTF-8</encoding.source>
<encoding.reporting>UTF-8</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
include::../maven/build-info/pom.xml[tags=build-info]
----

This configuration will generate a `build-info.properties` at the expected location with four additional keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,18 @@
== Getting Started
To use the Spring Boot Maven Plugin, include the appropriate XML in the `plugins` section of your `pom.xml`, as shown in the following example:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
include::../maven/getting-started/pom.xml[tags=getting-started]
----



If you use a milestone or snapshot release, you also need to add the appropriate `pluginRepository` elements, as shown in the following listing:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<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>
include::../maven/getting-started/plugin-repositories-pom.xml[tags=plugin-repositories]
----


Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,9 @@
While you may start your Spring Boot application very easily from your test (or test suite) itself, it may be desirable to handle that in the build itself.
To make sure that the lifecycle of your Spring Boot application is properly managed around your integration tests, you can use the `start` and `stop` goals, as shown in the following example:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
include::../maven/integration-tests/pom.xml[tags=integration-tests]
----

Such setup can now use the https://maven.apache.org/surefire/maven-failsafe-plugin[failsafe-plugin] to run your integration tests as you would expect.
Expand Down Expand Up @@ -54,64 +33,9 @@ When the `start` goal of the plugin is used, the Spring Boot application is star

The example below showcases how you could achieve the same feature using the https://www.mojohaus.org/build-helper-maven-plugin[Build Helper Maven Plugin]:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<arguments>
<argument>--server.port=${tomcat.http.port}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<test.server.port>${tomcat.http.port}</test.server.port>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
include::../maven/integration-tests/random-port-pom.xml[tags=random-port]
----

You can now retrieve the `test.server.port` system property in any of your integration test to create a proper `URL` to the server.
Expand All @@ -124,35 +48,9 @@ The `jmxPort` property allows to customize the port the plugin uses to communica

This example shows how you can customize the port in case `9001` is already used:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jmxPort>9009</jmxPort>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
include::../maven/integration-tests/customize-jmx-port-pom.xml[tags=customize-jmx-port]
----

TIP: If you need to configure the JMX port, make sure to do so in the global configuration as shown above so that it is shared by both goals.
Expand All @@ -165,48 +63,9 @@ The `skip` property allows to skip the execution of the Spring Boot maven plugin

This example shows how you can skip integration tests with a command-line property and still make sure that the `repackage` goal runs:

[source,xml,indent=0,subs="verbatim,attributes"]
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
<project>
<properties>
<skip.it>false</skip.it>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<skip>${skip.it}</skip>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<skip>${skip.it}</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>${skip.it}</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
include::../maven/integration-tests/skip-integration-tests-pom.xml[tags=skip-integration-tests]
----

By default, the integration tests will run but this setup allows you to easily disable them on the command-line as follows:
Expand Down
Loading