上一篇文章介紹了springboot依賴版本號管理的幾種方式,如今來詳細分析一下spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform是如何進行版本號控制的,各自有什麼做用和區別。java
從繼承的源點spring-boot-dependencies開始看git
dependencyManagement節點的做用是統一maven引入依賴JAR包的版本號,能夠看出spring-boot-dependencies最重要的一個做用就是對springboot可能用到的依賴JAR包作了版本號的控制管理web
pluginManagement節點的做用是統一maven引入插件的版本號,能夠看出spring-boot-dependencies另外一個做用是對springboot可能用到的插件作了版本號的控制管理spring
spring-boot-dependencies引入(或覆蓋)了三個插件:apache
maven-help-plugin:用於獲取有關項目或系統的幫助信息;這個插件是Maven自帶的插件,這裏進行了覆蓋設置;設置inherited(是否繼承)爲false;設置phase爲generate-resources、goal爲effective-pom的配置outputspringboot
<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:處理XML相關app
<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:用於設置主源碼目錄、測試源碼目錄、主資源文件目錄、測試資源文件目錄等maven
<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>
這三個插件共同完成了一件事,將spring-boot-dependencies(springboot在項目裏使用到的依賴)輸出到XML,而且打包install到倉庫。ide
這些就是spring-boot-dependencies主要的做用了,管理控制依賴版本號,管理控制插件版本號以及引入了3個輔助插件。spring-boot
spring-boot-starter-parent繼承spring-boot-dependencies
spring-boot-starter-parent在properties節點裏添加了一些預設配置
java.version:jdk的版本號
<java.version>1.6</java.version>
resource.delimiter:設定佔位符爲@
<resource.delimiter>@</resource.delimiter>
project.build.sourceEncoding、project.reporting.outputEncoding:設置編碼爲UTF-8
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.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>
覆蓋了spring-boot-dependencies的spring-core依賴引入,去掉了spring-core裏的commons-logging依賴
<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>
設置了application.properties配置文件的讀取目錄在/src/main/resources目錄下
<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>
覆蓋了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.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin>
maven-jar-plugin:添加了啓動類配置和掃描默認實現JAR包配置
<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:配置了Maven打包時單元測試掃描**/*Tests.java、**/*Test.java類,排除**/Abstract*.java類
<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:配置了能夠沒有web.xml文件進行啓動;添加了啓動類配置和掃描默認實現JAR包配置
<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:添加了啓動類配置
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <mainClass>${start-class}</mainClass> </configuration> </plugin>
maven-resources-plugin:配置了資源佔位符爲 @
<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:配置了綁定Maven打包修訂階段revision的GIT版本號變化;配了verbose爲ture;配置了日期格式爲yyyy-MM-dd'T'HH:mm:ssZ;配置了生成GIT .properties文件,文件名爲${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:配置了綁定Maven打包repackage階段插件的使用;配置了啓動類
<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:覆蓋引入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.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>
io.spring.platform繼承spring-boot-starter-parent
io.spring.platform一個最大的做用即是將通過集成測試的各種依賴版本號進行整合。
在平時開發中,須要某個JAR包依賴每每是習慣性的找最新版本,或是根據經驗選擇一個版本;
單對某個JAR包來說,沒有任何問題,但當過多的JAR包依賴整合到一塊兒的時候,就可能會出現各自版本不適配的狀況產生,產生BUG漏洞的場景將大大增長;
io.spring.platform所作的事情就是將作過集成測試JAR包依賴整合到一塊兒,大大下降了漏洞出現的可能性。
覆蓋全部父節點裏的依賴引入並增長部分新的依賴,使用properties節點裏的版本號
覆蓋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>
新增的插件: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>
這樣分析以後,對spring-boot-dependencies、spring-boot-starter-parent、io.spring.platform就有了基本的瞭解了。
這三者最主要的做用仍是管理各種依賴的版本控制。
咱們徹底能夠本身作一個pom來管理springboot的依賴引入版本管理,後續文章會展現。
對於pom裏各種插件引入的做用,後續也會詳細分析。
最終的目的是作到知其然,知其因此然,這樣開發起來纔會有大局觀。