『SpringBoot 源码分析』依赖管理

『SpringBoot 源码分析』依赖管理

  • 基于 2.2.9.RELEASE
  1. 问题:为什么导入 dependency 时不需要指定版本?
  • 在项目中的 pom.xml 文件中找到 spring-boot-starter-parent 依赖
<parent>
	<groupId>org.springframework.bootgroupId>
	<artifactId>spring-boot-starter-parentartifactId>
	<version>2.2.9.RELEASEversion>
	<relativePath/> 
parent>
  • 跳入 spring-boot-starter-parent 源文件,会发现 spring-bootstarter-parent 会有个父依赖 spring-boot-dependencies
 <parent>
   <groupId>org.springframework.bootgroupId>
   <artifactId>spring-boot-dependenciesartifactId>
   <version>2.2.9.RELEASEversion>
   <relativePath>../../spring-boot-dependenciesrelativePath>
 parent>
  • 再次点击进入 spring-boot-dependencies 会发现一堆属性配置
 <properties>
    <activemq.version>5.15.11activemq.version>
    <antlr2.version>2.7.7antlr2.version>
    <appengine-sdk.version>1.9.77appengine-sdk.version>
    <artemis.version>2.10.1artemis.version>
    <aspectj.version>1.9.5aspectj.version>
    <assertj.version>3.13.2assertj.version>
    <atomikos.version>4.0.6atomikos.version>
    <awaitility.version>4.0.1awaitility.version>
    <bitronix.version>2.1.4bitronix.version>
    <build-helper-maven-plugin.version>3.0.0build-helper-maven-plugin.version>
    <byte-buddy.version>1.10.4byte-buddy.version>
     ...
  properties>
  • 同时相应的已经有常用组件的依赖配置,所以就在 pom.xml 配置的时候,不需要配置版号
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-bootartifactId>
        <version>2.2.9.RELEASEversion>
      dependency>
      <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-testartifactId>
        <version>2.2.9.RELEASEversion>
      dependency>
    ...
   dependencies>
dependencyManagement>

你可能感兴趣的:(『后端』,spring,boot,java,spring)