Spring Boot源码阅读环境搭建

基于SpringBoot 2.3.9.RELEASE 版本

前期准备

如果希望搭建SpringBoot源码阅读环境,必须科学上网,不要相信使用国内源下载依赖,阿里的源会有问题

流程

  1. 克隆代码,切换到2.3.9.release分支,导入IDE

  2. 这里如果下载依赖正常,通常还是会报错的,需要注释掉源码中的两处

  • settings.gradle中注释掉’io.spring.ge.conventions’

    1
    2
    3
    4
    plugins {
    id "com.gradle.enterprise" version "3.5.2"
    // id "io.spring.ge.conventions" version "0.0.7"
    }
  • buildSrcbuild.gradle中注释掉io.spring.javaformat

    1
    2
    3
    4
    5
    plugins {
    id "java-gradle-plugin"
    //id "io.spring.javaformat" version "${javaFormatVersion}"
    id "checkstyle"
    }

补充说明

一般下载完依赖,注释掉格式化等插件就可以直接在IDE中运行spring-boot-tests下的测试用例了
但我选择在源码根目录下新建spring-boot-test模块然后新建一个正常的SpringBoot程序,只不过引用的是源码中的依赖
我使用的版本是v2.3.9.release版,使用gradle做依赖管理,下面是build.gradle示例

1
2
3
4
5
6
7
8
9
10
11
12
plugins {
id 'java'
id "org.springframework.boot.conventions"
}

description = "Spring Boot Test test"

dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))

testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
}