Details of spring boot dependencies, spring boot starter parent, io.spring.platform

The previous article introduced several methods of spring boot dependent version number management. Now let's analyze in detail how spring boot dependencies, spring boot starter parent and io.spring.platform control version number, and what are their functions and differences.

I. spring boot dependencies, spring boot starter parent and io.spring.platform are inheritance relationships.

1. Spring boot starter parent inherits spring boot dependencies

 

2.io.spring.platform inherits spring boot starter parent

 

Spring boot dependencies

Starting from the inherited spring boot dependencies

1. Dependency management node in pom.xml

The function of the dependency management node is to unify the version number of dependent JAR packages introduced by maven. It can be seen that the most important function of spring boot dependencies is to control and manage the version number of dependent JAR packages that spring boot may use.

2. Plugin management node in pom.xml

The function of the plugin management node is to unify the version number of plug-ins introduced by maven. It can be seen that another function of spring boot dependencies is to control and manage the version number of plug-ins that spring boot may use.

3. plugins node in pom.xml

Spring boot dependencies introduces three plug-ins:

Maven help plugin: used to get help information about a project or system;

<plugin>
  <artifactId>maven-help-plugin</artifactId>
  <inherited>false</inherited>
  <executions>
    <execution>
      <id>generate-effective-dependencies-pom</id>
      <phase>generate-resources</phase>
      <goals>
        <goal>effective-pom</goal>
      </goals>
      <configuration>
        <output>${project.build.directory}/effective-pom/spring-boot-dependencies.xml</output>
      </configuration>
    </execution>
  </executions>
</plugin>

XML Maven plugin: dealing with XML correlation

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>xml-maven-plugin</artifactId>
  <version>1.0</version>
  <inherited>false</inherited>
  <executions>
    <execution>
      <goals>
        <goal>transform</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <transformationSets>
      <transformationSet>
        <dir>${project.build.directory}/effective-pom</dir>
        <stylesheet>src/main/xslt/single-project.xsl</stylesheet>
        <outputDir>${project.build.directory}/effective-pom</outputDir>
      </transformationSet>
    </transformationSets>
  </configuration>
</plugin>

Build helper Maven plugin: used to set the main source directory, test source directory, main resource file directory, test resource file directory, etc.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <inherited>false</inherited>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>${project.build.directory}/effective-pom/spring-boot-dependencies.xml</file>
            <type>effective-pom</type>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>

These are the main functions of spring boot dependencies, including the version number of management control dependency, the version number of management control plug-ins and the introduction of three auxiliary plug-ins.

III. spring boot starter parent

Spring boot starter parent inherits spring boot dependencies

1. properties node in pom.xml

Spring boot starter parent adds some default configurations to the properties node

java.version: version number of jdk

<java.version>1.6</java.version>

resource.delimiter: set placeholder to@

<resource.delimiter>@</resource.delimiter>

project.build.sourceEncoding, project.reporting.outputEncoding: set the encoding to UTF-8

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

maven.compiler.source, maven.compiler.target: set the jdk version of compilation package

<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

2. Dependency management node in pom.xml

It covers the introduction of spring core dependency in spring boot dependencies and removes commons logging dependency in spring core.

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>${spring.version}</version>
  <exclusions>
    <exclusion>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>

3. Build - > resources node in pom.xml

The reading directory of the application.properties configuration file is set in the / src/main/resources directory.

<resource>
  <directory>${basedir}/src/main/resources</directory>
  <filtering>true</filtering>
  <includes>
    <include>**/application*.yml</include>
    <include>**/application*.yaml</include>
    <include>**/application*.properties</include>
  </includes>
</resource>
<resource>
  <directory>${basedir}/src/main/resources</directory>
  <excludes>
    <exclude>**/application*.yml</exclude>
    <exclude>**/application*.yaml</exclude>
    <exclude>**/application*.properties</exclude>
  </excludes>
</resource>

4. pluginManagement node in pom.xml

Covering some plug-in version control management of spring boot dependencies: Maven failsafe plugin, Maven jar plugin, Maven surefire plugin, Maven war plugin, exec Maven plugin, Maven resources plugin, GIT commit ID plugin, spring boot Maven plugin, Maven shade plugin

Maven failsafe plugin: configured the integration test and verify phases when Binding maven

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Maven JAR plugin: added startup class configuration and scan default implementation JAR package configuration

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>${start-class}</mainClass>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
      </manifest>
    </archive>
  </configuration>
</plugin>

Maven surefire plugin: configured Maven package time unit test scanning * * / * Tests.java, * * / * Test.java classes, excluding * * / Abstract*.java classes

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <includes>
      <include>**/*Tests.java</include>
      <include>**/*Test.java</include>
    </includes>
    <excludes>
      <exclude>**/Abstract*.java</exclude>
    </excludes>
  </configuration>
</plugin>

Maven war plugin: configured to start without web.xml file; added startup class configuration and scan to implement JAR package configuration by default

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <archive>
      <manifest>
        <mainClass>${start-class}</mainClass>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
      </manifest>
    </archive>
  </configuration>
</plugin>

Exec Maven plugin: added startup class configuration

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <configuration>
    <mainClass>${start-class}</mainClass>
  </configuration>
</plugin>

Maven resources plugin: configured resource placeholders as@

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.6</version>
  <configuration>
    <delimiters>
      <delimiter>${resource.delimiter}</delimiter>
    </delimiters>
    <useDefaultDelimiters>false</useDefaultDelimiters>
  </configuration>
</plugin>

Git commit ID plugin: it is configured to bind the change of GIT version number of Maven package revision stage revision; it is configured with verbose as ture; it is configured with date format as yyyy mm dd't'hh: mm: SSZ; it is configured to generate GIT. Properties file with the name of ${project.build.outputDirectory}/git.properties.

<plugin>
  <groupId>pl.project13.maven</groupId>
  <artifactId>git-commit-id-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>revision</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <verbose>true</verbose>
    <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
    <generateGitPropertiesFile>true</generateGitPropertiesFile>
    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
  </configuration>
</plugin>

Spring boot Maven plugin: configured the use of plug-ins in the packaging and repackage phase of binding Maven; configured the startup class

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

Maven shade plugin: overwrite the introduction of spring boot Maven plugin dependency JAR; configure keepDependenciesWithProvidedScope to be true; configure createDependencyReducedPom to be true; filter out META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA to prevent repeated reference packaging failure; configure and bind Maven packaging stage shade;

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.5.4.RELEASE</version>
    </dependency>
  </dependencies>
  <configuration>
    <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
    <createDependencyReducedPom>true</createDependencyReducedPom>
    <filters>
      <filter>
        <artifact>*:*</artifact>
        <excludes>
          <exclude>META-INF/*.SF</exclude>
          <exclude>META-INF/*.DSA</exclude>
          <exclude>META-INF/*.RSA</exclude>
        </excludes>
      </filter>
    </filters>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>META-INF/spring.handlers</resource>
          </transformer>
          <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
            <resource>META-INF/spring.factories</resource>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>META-INF/spring.schemas</resource>
          </transformer>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <mainClass>${start-class}</mainClass>
          </transformer>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>

IV. io.spring.platform

io.spring.platform inherits spring boot starter parent

1. properties node in pom.xml

One of the biggest functions of io.spring.platform is to integrate all kinds of dependent version numbers that have been integrated and tested.

In normal development, it is customary to find the latest version or select a version based on experience when a JAR package is needed.

For a single JAR package, there is no problem, but when too many JAR packages rely on integration together, there may be different versions of mismatches, which will greatly increase the BUG vulnerability scenarios.

What io.spring.platform does is to integrate the JAR package dependencies that have been integrated and tested, which greatly reduces the possibility of vulnerabilities.

2. Dependency management node in pom.xml

Overwrite all dependencies in the parent node and add some new ones. Use the version number in the properties node.

3. plugins node in pom.xml

Plug in to override spring boot dependencies: Maven help plugin

maven-help-plugin:

<plugin>
  <artifactId>maven-help-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-effective-dependencies-pom</id>
      <phase>generate-resources</phase>
      <goals>
        <goal>effective-pom</goal>
      </goals>
      <configuration>
        <output>${project.build.directory}/effective-pom.xml</output>
      </configuration>
    </execution>
  </executions>
  <inherited>false</inherited>
</plugin>

New plug-ins: gmavenplus plugin, build helper Maven plugin

gmavenplus-plugin:

<plugin>
  <groupId>org.codehaus.gmavenplus</groupId>
  <artifactId>gmavenplus-plugin</artifactId>
  <version>1.1</version>
  <executions>
    <execution>
      <goals>
        <goal>execute</goal>
      </goals>
      <phase>test</phase>
    </execution>
  </executions>
  <configuration>
    <scripts>
      <script>file:///${project.basedir}/src/main/groovyScripts/generateBomPropertiesFile.groovy</script>
    </scripts>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.3.0</version>
    </dependency>
  </dependencies>
  <inherited>false</inherited>
</plugin>

build-helper-maven-plugin:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>${project.build.directory}/platform-bom.properties</file>
            <type>properties</type>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
  <inherited>false</inherited>
</plugin>

 

After this analysis, we have a basic understanding of spring boot dependencies, spring boot starter parent, io.spring.platform.

The most important role of these three is to manage the version control of all kinds of dependencies.

We can make a pom to manage the dependency of springboot and introduce version management, which will be shown in the following articles.

The function of various plug-ins in pom will be analyzed in detail later.

The ultimate goal is to know what it is and why it is. Only in this way can we have the overall situation.

Keywords: Java Maven Spring xml

Added by Mijii on Thu, 24 Oct 2019 11:40:35 +0300