spring-boot-maven-plugin of the Maven plugin series

Spring Boot's Maven plugin (Spring Boot Maven plugin) can provide Spring Boot support for applications in a Maven way, that is, it provides Spring Boot applications with the possibility to perform Maven operations.
The Spring Boot Maven plugin can package a Spring Boot application as an executable jar or war file, and then run the Spring Boot application in the usual way.
The latest version of Spring Boot Maven plugin is 1.5.4.RELEASE released in 2017.6.8, which requires Java 8, Maven 3.2 and later.

5 Goals for Spring Boot Maven plugin

  • spring-boot:repackage, default goal. After mvn package, package the executable jar/war again, while keeping the jar/war generated by mvn package as .origin
  • spring-boot:run, run the Spring Boot application
  • spring-boot:start, in the mvn integration-test stage, manage the Spring Boot application life cycle
  • spring-boot:stop, in the mvn integration-test stage, manage the Spring Boot application life cycle
  • spring-boot:build-info, generate the build information file build-info.properties used by Actuator

2. Configure the pom.xml file

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.1.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

3.mvn package spring-boot:repackage说明

The main goal of Spring Boot Maven plugin is repackage, which can repackage the package generated by mvn package into an executable package during the package life cycle of Maven, and rename the package generated by mvn package to * .original.

Based on the above configuration, execute the following command on a project that generates a Jar package

mvn package spring-boot:repackage  

You can see the two jar files generated, one is *.jar and the other is *.jar.original.

 

In the process of executing the above command, Maven first packages and generates *.jar files in the package phase; then executes spring-boot:repackage to repackage, and looks for the Main-Class property configured in the Manifest file, as shown below:

Manifest-Version: 1.0  
Implementation-Title: gs-consuming-rest  
Implementation-Version: 0.1.0  
Archiver-Version: Plexus Archiver  
Built-By: exihaxi  
Implementation-Vendor-Id: org.springframework  
Spring-Boot-Version: 1.5.3.RELEASE  
Implementation-Vendor: Pivotal Software, Inc.  
Main-Class: org.springframework.boot.loader.JarLauncher  
Start-Class: com.ericsson.ramltest.MyApplication  
Spring-Boot-Classes: BOOT-INF/classes/  
Spring-Boot-Lib: BOOT-INF/lib/  
Created-By: Apache Maven 3.5.0  
Build-Jdk: 1.8.0_131  

Note that the value of the Main-Class property is org.springframework.boot.loader.JarLauncher;

The value of the Start-Class property is com.ericsson.ramltest.MyApplication.

The main() method is defined in the com.ericsson.ramltest.MyApplication class, which is the entry point of the program.

Usually, the Spring Boot Maven plugin will automatically set the Main-Class property for the Manifest file during the packaging process. In fact, the geometry of this property can also be controlled by the configuration property layout of the Spring Boot Maven plugin. The example is as follows

<plugin>  
  <groupId>org.springframework.boot</groupId>  
  <artifactId>spring-boot-maven-plugin</artifactId>  
  <version>1.5.4.RELEASE</version>  
  <configuration>  
    <mainClass>${start-class}</mainClass>  
    <layout>ZIP</layout>  
  </configuration>  
  <executions>  
    <execution>  
      <goals>  
        <goal>repackage</goal>  
      </goals>  
    </execution>  
  </executions>  
</plugin> 

Note that the layout property value here is ZIP.

 

The value of the layout attribute can be as follows:

  • JAR, the usual executable jar

Main-Class: org.springframework.boot.loader.JarLauncher

  • WAR, the usual executable war, requires servlet container dependencies located in WEB-INF/lib-provided

Main-Class: org.springframework.boot.loader.warLauncher

  • ZIP, or DIR, is similar to JAR

Main-Class: org.springframework.boot.loader.PropertiesLauncher

  • MODULE, which packages all dependent libraries (except those whose scope is provided), but does not package any Launcher of Spring Boot
  • NONE, package all dependent libraries, but do not package any Launcher of Spring Boot

4. Start/stop of Spring Boot Maven plugin in integration-test phase

<properties>  
  <it.skip>false</it.skip>  
</properties>  
<build>  
  <plugins>  
    <plugin>  
      <groupId>org.apache.maven.plugins</groupId>  
      <artifactId>maven-failsafe-plugin</artifactId>  
      <configuration>  
        <skip>${it.skip}</skip>  
      </configuration>  
    </plugin>  
    <plugin>  
      <groupId>org.springframework.boot</groupId>  
      <artifactId>spring-boot-maven-plugin</artifactId>  
      <version>1.5.4.RELEASE</version>  
      <executions>  
        <execution>  
          <id>pre-integration-test</id>  
          <goals>  
            <goal>start</goal>  
          </goals>  
          <configuration>  
            <skip>${it.skip}</skip>  
          </configuration>  
        </execution>  
        <execution>  
          <id>post-integration-test</id>  
          <goals>  
            <goal>stop</goal>  
          </goals>  
          <configuration>  
            <skip>${it.skip}</skip>  
          </configuration>  
        </execution>  
      </executions>  
    </plugin>  
  </plugins>  
</build>  

Note that the it.skip variable is used as a flag to skip integration-test.

maven-failsafe-plugin is used as the main execution target for integration-test.

The spring-boot-maven-plugin is used to provide support for integration-test.

The Maven command to execute integration-test is as follows:

mvn verify

or

mvn verify -Dit.skip=false

Reference link: 68. Spring Boot Maven Plugin

http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/maven-plugin/
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325813672&siteId=291194637