spring |
您所在的位置:网站首页 › spring-boot-starter-parent作用 › spring |
上一篇文章介绍了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-dependencies2.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:用于获取有关项目或系统的帮助信息;这个插件是Maven自带的插件,这里进行了覆盖设置;设置inherited(是否继承)为false;设置phase为generate-resources、goal为effective-pom的配置output maven-help-plugin false generate-effective-dependencies-pom generate-resources effective-pom ${project.build.directory}/effective-pom/spring-boot-dependencies.xmlxml-maven-plugin:处理XML相关 org.codehaus.mojo xml-maven-plugin 1.0 false transform ${project.build.directory}/effective-pom src/main/xslt/single-project.xsl ${project.build.directory}/effective-pombuild-helper-maven-plugin:用于设置主源码目录、测试源码目录、主资源文件目录、测试资源文件目录等 org.codehaus.mojo build-helper-maven-plugin false attach-artifacts package attach-artifact ${project.build.directory}/effective-pom/spring-boot-dependencies.xml effective-pom这三个插件共同完成了一件事,将spring-boot-dependencies(springboot在项目里使用到的依赖)输出到XML,并且打包install到仓库。 这些就是spring-boot-dependencies主要的作用了,管理控制依赖版本号,管理控制插件版本号以及引入了3个辅助插件。 三、spring-boot-starter-parentspring-boot-starter-parent继承spring-boot-dependencies 1.pom.xml里的properties节点spring-boot-starter-parent在properties节点里添加了一些预设配置 java.version:jdk的版本号 1.6resource.delimiter:设定占位符为@ @project.build.sourceEncoding、project.reporting.outputEncoding:设置编码为UTF-8 UTF-8 UTF-8maven.compiler.source、maven.compiler.target:设置编译打包的jdk版本 ${java.version} ${java.version} 2.pom.xml里的dependencyManagement节点覆盖了spring-boot-dependencies的spring-core依赖引入,去掉了spring-core里的commons-logging依赖 org.springframework spring-core ${spring.version} commons-logging commons-logging 3.pom.xml里的bulid->resources节点设置了application.properties配置文件的读取目录在/src/main/resources目录下 ${basedir}/src/main/resources true **/application*.yml **/application*.yaml **/application*.properties ${basedir}/src/main/resources **/application*.yml **/application*.yaml **/application*.properties 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阶段 org.apache.maven.plugins maven-failsafe-plugin integration-test verifymaven-jar-plugin:添加了启动类配置和扫描默认实现JAR包配置 org.apache.maven.plugins maven-jar-plugin ${start-class} truemaven-surefire-plugin:配置了Maven打包时单元测试扫描**/*Tests.java、**/*Test.java类,排除**/Abstract*.java类 org.apache.maven.plugins maven-surefire-plugin **/*Tests.java **/*Test.java **/Abstract*.javamaven-war-plugin:配置了可以没有web.xml文件进行启动;添加了启动类配置和扫描默认实现JAR包配置 org.apache.maven.plugins maven-war-plugin false ${start-class} trueexec-maven-plugin:添加了启动类配置 org.codehaus.mojo exec-maven-plugin ${start-class}maven-resources-plugin:配置了资源占位符为 @ org.apache.maven.plugins maven-resources-plugin 2.6 ${resource.delimiter} falsegit-commit-id-plugin:配置了绑定Maven打包修订阶段revision的GIT版本号变化;配了verbose为ture;配置了日期格式为yyyy-MM-dd'T'HH:mm:ssZ;配置了生成GIT .properties文件,文件名为${project.build.outputDirectory}/git.properties pl.project13.maven git-commit-id-plugin revision true yyyy-MM-dd'T'HH:mm:ssZ true ${project.build.outputDirectory}/git.propertiesspring-boot-maven-plugin:配置了绑定Maven打包repackage阶段插件的使用;配置了启动类 org.springframework.boot spring-boot-maven-plugin repackage ${start-class}maven-shade-plugin:覆盖引入spring-boot-maven-plugin依赖JAR;配置keepDependenciesWithProvidedScope为true;配置createDependencyReducedPom为true;过滤掉META-INF/*.SF、META-INF/*.DSA、META-INF/*.RSA,防止重复引用打包失败;配置绑定Maven打包package阶段shade; org.apache.maven.plugins maven-shade-plugin org.springframework.boot spring-boot-maven-plugin 1.5.4.RELEASE true true *:* META-INF/*.SF META-INF/*.DSA META-INF/*.RSA package shade META-INF/spring.handlers META-INF/spring.factories META-INF/spring.schemas ${start-class} 四、io.spring.platformio.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: maven-help-plugin generate-effective-dependencies-pom generate-resources effective-pom ${project.build.directory}/effective-pom.xml false新增的插件:gmavenplus-plugin、build-helper-maven-plugin gmavenplus-plugin: org.codehaus.gmavenplus gmavenplus-plugin 1.1 execute test file:///${project.basedir}/src/main/groovyScripts/generateBomPropertiesFile.groovy org.codehaus.groovy groovy-all 2.3.0 falsebuild-helper-maven-plugin: org.codehaus.mojo build-helper-maven-plugin attach-artifacts package attach-artifact ${project.build.directory}/platform-bom.properties properties false
这样分析之后,对spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform就有了基本的了解了。 这三者最主要的作用还是管理各类依赖的版本控制。 我们完全可以自己做一个pom来管理springboot的依赖引入版本管理,后续文章会展示。 对于pom里各类插件引入的作用,后续也会详细分析。 最终的目的是做到知其然,知其所以然,这样开发起来才会有大局观。 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |