上一篇文章介绍了springboot依赖版本号管理的几种方式,现在来详细分析一下spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform是如何进行版本号控制的,各自有什么作用和区别。
一、spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform三者是继承关系
1.spring-boot-starter-parent继承spring-boot-dependencies
2.io.spring.platform继承spring-boot-starter-parent
二、spring-boot-dependencies
从继承的源点spring-boot-dependencies开始看
1.pom.xml里的dependencyManagement节点
dependencyManagement节点的作用是统一maven引入依赖JAR包的版本号,可以看出spring-boot-dependencies最重要的一个作用就是对springboot可能用到的依赖JAR包做了版本号的控制管理
2.pom.xml里的pluginManagement节点
pluginManagement节点的作用是统一maven引入插件的版本号,可以看出spring-boot-dependencies另一个作用是对springboot可能用到的插件做了版本号的控制管理
3.pom.xml里的plugins节点
spring-boot-dependencies引入了三个插件:
maven-help-plugin:用于获取有关项目或系统的帮助信息;
<plugin> <artifactId>maven-help-pluginartifactId> <inherited>falseinherited> <executions> <execution> <id>generate-effective-dependencies-pomid> <phase>generate-resourcesphase> <goals> <goal>effective-pomgoal> goals> <configuration> <output>${project.build.directory}/effective-pom/spring-boot-dependencies.xmloutput> configuration> execution> executions> plugin>
xml-maven-plugin:处理XML相关
<plugin> <groupId>org.codehaus.mojogroupId> <artifactId>xml-maven-pluginartifactId> <version>1.0version> <inherited>falseinherited> <executions> <execution> <goals> <goal>transformgoal> goals> execution> executions> <configuration> <transformationSets> <transformationSet> <dir>${project.build.directory}/effective-pomdir> <stylesheet>src/main/xslt/single-project.xslstylesheet> <outputDir>${project.build.directory}/effective-pomoutputDir> transformationSet> transformationSets> configuration> plugin>
build-helper-maven-plugin:用于设置主源码目录、测试源码目录、主资源文件目录、测试资源文件目录等
<plugin> <groupId>org.codehaus.mojogroupId> <artifactId>build-helper-maven-pluginartifactId> <inherited>falseinherited> <executions> <execution> <id>attach-artifactsid> <phase>packagephase> <goals> <goal>attach-artifactgoal> goals> <configuration> <artifacts> <artifact> <file>${project.build.directory}/effective-pom/spring-boot-dependencies.xmlfile> <type>effective-pomtype> artifact> artifacts> configuration> execution> executions> plugin>
这些就是spring-boot-dependencies主要的作用了,管理控制依赖版本号,管理控制插件版本号以及引入了3个辅助插件。
三、spring-boot-starter-parent
spring-boot-starter-parent继承spring-boot-dependencies
1.pom.xml里的properties节点
spring-boot-starter-parent在properties节点里添加了一些预设配置
java.version:jdk的版本号
<java.version>1.6java.version>
resource.delimiter:设定占位符为@
<resource.delimiter>@resource.delimiter>
project.build.sourceEncoding、project.reporting.outputEncoding:设置编码为UTF-8
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
maven.compiler.source、maven.compiler.target:设置编译打包的jdk版本
<maven.compiler.source>${java.version}maven.compiler.source> <maven.compiler.target>${java.version}maven.compiler.target>
2.pom.xml里的dependencyManagement节点
覆盖了spring-boot-dependencies的spring-core依赖引入,去掉了spring-core里的commons-logging依赖
<dependency> <groupId>org.springframeworkgroupId> <artifactId>spring-coreartifactId> <version>${spring.version}version> <exclusions> <exclusion> <groupId>commons-logginggroupId> <artifactId>commons-loggingartifactId> exclusion> exclusions> dependency>
3.pom.xml里的bulid->resources节点
设置了application.properties配置文件的读取目录在/src/main/resources目录下
<resource> <directory>${basedir}/src/main/resourcesdirectory> <filtering>truefiltering> <includes> <include>**/application*.ymlinclude> <include>**/application*.yamlinclude> <include>**/application*.propertiesinclude> includes> resource> <resource> <directory>${basedir}/src/main/resourcesdirectory> <excludes> <exclude>**/application*.ymlexclude> <exclude>**/application*.yamlexclude> <exclude>**/application*.propertiesexclude> excludes> resource>
4.pom.xml里的pluginManagement节点
覆盖了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:配置了绑定Maven打包时integration-test、verify阶段
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-failsafe-pluginartifactId> <executions> <execution> <goals> <goal>integration-testgoal> <goal>verifygoal> goals> execution> executions> plugin>
maven-jar-plugin:添加了启动类配置和扫描默认实现JAR包配置
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-jar-pluginartifactId> <configuration> <archive> <manifest> <mainClass>${start-class}mainClass> <addDefaultImplementationEntries>trueaddDefaultImplementationEntries> manifest> archive> configuration> plugin>
maven-surefire-plugin:配置了Maven打包时单元测试扫描**/*Tests.java、**/*Test.java类,排除**/Abstract*.java类
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-surefire-pluginartifactId> <configuration> <includes> <include>**/*Tests.javainclude> <include>**/*Test.javainclude> includes> <excludes> <exclude>**/Abstract*.javaexclude> excludes> configuration> plugin>
maven-war-plugin:配置了可以没有web.xml文件进行启动;添加了启动类配置和扫描默认实现JAR包配置
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-war-pluginartifactId> <configuration> <failOnMissingWebXml>falsefailOnMissingWebXml> <archive> <manifest> <mainClass>${start-class}mainClass> <addDefaultImplementationEntries>trueaddDefaultImplementationEntries> manifest> archive> configuration> plugin>
exec-maven-plugin:添加了启动类配置
<plugin> <groupId>org.codehaus.mojogroupId> <artifactId>exec-maven-pluginartifactId> <configuration> <mainClass>${start-class}mainClass> configuration> plugin>
maven-resources-plugin:配置了资源占位符为 @
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-resources-pluginartifactId> <version>2.6version> <configuration> <delimiters> <delimiter>${resource.delimiter}delimiter> delimiters> <useDefaultDelimiters>falseuseDefaultDelimiters> configuration> plugin>
git-commit-id-plugin:配置了绑定Maven打包修订阶段revision的GIT版本号变化;配了verbose为ture;配置了日期格式为yyyy-MM-dd'T'HH:mm:ssZ;配置了生成GIT .properties文件,文件名为${project.build.outputDirectory}/git.properties
<plugin> <groupId>pl.project13.mavengroupId> <artifactId>git-commit-id-pluginartifactId> <executions> <execution> <goals> <goal>revisiongoal> goals> execution> executions> <configuration> <verbose>trueverbose> <dateFormat>yyyy-MM-dd'T'HH:mm:ssZdateFormat> <generateGitPropertiesFile>truegenerateGitPropertiesFile> <generateGitPropertiesFilename>${project.build.outputDirectory}/git.propertiesgenerateGitPropertiesFilename> configuration> plugin>
spring-boot-maven-plugin:配置了绑定Maven打包repackage阶段插件的使用;配置了启动类
<plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> <executions> <execution> <goals> <goal>repackagegoal> goals> execution> executions> <configuration> <mainClass>${start-class}mainClass> configuration> plugin>
maven-shade-plugin:覆盖引入spring-boot-maven-plugin依赖JAR;配置keepDependenciesWithProvidedScope为true;配置createDependencyReducedPom为true;过滤掉META-INF/*.SF、META-INF/*.DSA、META-INF/*.RSA,防止重复引用打包失败;配置绑定Maven打包package阶段shade;
<plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-shade-pluginartifactId> <dependencies> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> <version>1.5.4.RELEASEversion> dependency> dependencies> <configuration> <keepDependenciesWithProvidedScope>truekeepDependenciesWithProvidedScope> <createDependencyReducedPom>truecreateDependencyReducedPom> <filters> <filter> <artifact>*:*artifact> <excludes> <exclude>META-INF/*.SFexclude> <exclude>META-INF/*.DSAexclude> <exclude>META-INF/*.RSAexclude> excludes> filter> filters> configuration> <executions> <execution> <phase>packagephase> <goals> <goal>shadegoal> goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlersresource> transformer> <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer"> <resource>META-INF/spring.factoriesresource> transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemasresource> 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>
四、io.spring.platform
io.spring.platform继承spring-boot-starter-parent
1.pom.xml里的properties节点
io.spring.platform一个最大的作用便是将经过集成测试的各类依赖版本号进行整合。
在平时开发中,需要某个JAR包依赖往往是习惯性的找最新版本,或是根据经验选择一个版本;
单对某个JAR包来讲,没有任何问题,但当过多的JAR包依赖整合到一起的时候,就可能会出现各自版本不适配的情况产生,产生BUG漏洞的场景将大大增加;
io.spring.platform所做的事情就是将做过集成测试JAR包依赖整合到一起,大大降低了漏洞出现的可能性。
2.pom.xml里的dependencyManagement节点
覆盖所有父节点里的依赖引入并增加部分新的依赖,使用properties节点里的版本号
3.pom.xml里的plugins节点
覆盖spring-boot-dependencies的插件:maven-help-plugin
maven-help-plugin:
<plugin> <artifactId>maven-help-pluginartifactId> <executions> <execution> <id>generate-effective-dependencies-pomid> <phase>generate-resourcesphase> <goals> <goal>effective-pomgoal> goals> <configuration> <output>${project.build.directory}/effective-pom.xmloutput> configuration> execution> executions> <inherited>falseinherited> plugin>
新增的插件:gmavenplus-plugin、build-helper-maven-plugin
gmavenplus-plugin:
<plugin> <groupId>org.codehaus.gmavenplusgroupId> <artifactId>gmavenplus-pluginartifactId> <version>1.1version> <executions> <execution> <goals> <goal>executegoal> goals> <phase>testphase> execution> executions> <configuration> <scripts> <script>file:///${project.basedir}/src/main/groovyScripts/generateBomPropertiesFile.groovyscript> scripts> configuration> <dependencies> <dependency> <groupId>org.codehaus.groovygroupId> <artifactId>groovy-allartifactId> <version>2.3.0version> dependency> dependencies> <inherited>falseinherited> plugin>
build-helper-maven-plugin:
<plugin> <groupId>org.codehaus.mojogroupId> <artifactId>build-helper-maven-pluginartifactId> <executions> <execution> <id>attach-artifactsid> <phase>packagephase> <goals> <goal>attach-artifactgoal> goals> <configuration> <artifacts> <artifact> <file>${project.build.directory}/platform-bom.propertiesfile> <type>propertiestype> artifact> artifacts> configuration> execution> executions> <inherited>falseinherited> plugin>
这样分析之后,对spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform就有了基本的了解了。
这三者最主要的作用还是管理各类依赖的版本控制。
我们完全可以自己做一个pom来管理springboot的依赖引入版本管理,后续文章会展示。
对于pom里各类插件引入的作用,后续也会详细分析。
最终的目的是做到知其然,知其所以然,这样开发起来才会有大局观。