Idea导入SpringBoot源码终极版
一、导入Spring源码的准备
- 本人工具及环境介绍
Windows 10
+IDEA 2020.1
+JDK 11.0.9
+Gradle 6.5
+spring-boot 2.5.0-SNAPSHOT
1.1 Gradle的下载和配置
- 官网地址
https://gradle.org/releases/
- 版本选择
找到对应的版本,选择binary-only
- 配置环境变量
解压后,别放中文路径兄弟
① 新建系统变量GRADLE_HOME
② 新建仓库系统变量GRADLE_USER_HOME
③path
中添加%GRADLE_HOME%\bin
④ 检查是否配置成功
gradle -v
1.2 IDEA集成Gradle
- 依次执行如下步骤
Settings
->Build
->Gradle
1.3 下载SpringBoot源码
- 下载方式
① 下载源码zip
包,然后导入,不建议
② 从GitHub
上检出源码,不仅能及时更新代码,还有很清楚的代码更新记录,岂不是爽歪歪
https://github.com/spring-projects/spring-boot
二、导入及避坑
2.1 导入源码
- 源码包导入步骤(如果是通过代码检出的方式请忽略此步骤)
① 在Idea
中依次File -> Open
② 找到源码包文件夹,并选择build.gradle
2.2 避坑的地方
- 为了防止
build
的过程很慢,检查Idea的运行内存并调整
① 修改配置文件
② 修改运行内存
- 依赖下载很慢的问题
我下载的速度很慢,按照 网上说的调整了镜像似乎什么用都没有,每次出现下载失败的问题,直接重新build
就好
三、增加测试模块试运行
3.1 新建测试模块
- 新建测试模块
① 新建Gradle 模块
② 配置locatiion
和name
- 配置当前模块的
build.gradle
plugins {
id 'java'
}
group 'org.springframework.boot'
version '2.5.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor(project(":spring-boot-project:spring-boot-tools:spring-boot-configuration-processor"))
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
implementation(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
implementation(project(":spring-boot-project:spring-boot"))
implementation("jakarta.validation:jakarta.validation-api")
}
- 创建测试demo
package org.springframework.debug;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author: yangbh29924
* @date: Dec 26, 2020
**/
@RestController
@EnableAutoConfiguration
@SpringBootConfiguration
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
- 运行并测试