Spring5源码导入idea

idea版本:2020.2.3
spring版本:5.0.2
gradle版本:4.3.1

一、下载Spring源码

链接:https://github.com/spring-projects/spring-framework/tree/5.0.x
(本次Spring源码下载版本为5.0.2,点击此处直接下载
Spring5源码导入idea

二、下载编译gradle

由于spring采用gradle编译,所以需要先进行gradle安装。

1、下载

链接:https://gradle.org/releases/
(本次Gradle下载版本为4.3.1,点击此处直接下载

2、配置环境变量

1)下载后解压
2)新建系统变量: GRADLE_HOME
3)追加到系统变量PATH中: %GRADLE_HOME%\bin

3、查看是否安装成功

cmd唤出命令行,执行 gradle -v
显示如下信息,代表gradle安装完成
Spring5源码导入idea

三、编译

1、执行编译指令

cmd命令行,切换至spring源码根目录,执行如下命令 gradle.bat
Spring5源码导入idea

2、编译时错误

(如果成功编译,可跳过)

1)错误一

FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project ‘spring’.
-Could not resolve all artifacts for configuration ‘:classpath’.
-Could not find org.jetbrains.dokka:integration:0.9.15.
Searched in the following locations:
https://plugins.gradle.org/m2/org/jetbrains/dokka/integration/0.9.15/integration-0.9.15.pom
https://plugins.gradle.org/m2/org/jetbrains/dokka/integration/0.9.15/integration-0.9.15.jar
https://repo.spring.io/plugins-release/org/jetbrains/dokka/integration/0.9.15/integration-0.9.15.pom
https://repo.spring.io/plugins-release/org/jetbrains/dokka/integration/0.9.15/integration-0.9.15.jar
Required by:
project : > org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin:0.9.15 > org.jetbrains.dokka:dokka-gradle-plugin:0.9.15
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Spring5源码导入idea
解决方法:修改 D:\spring-framework-5.0.2.RELEASE\build.gradle 文件
注掉 id “org.jetbrains.dokka” version “0.9.15” 语句
新增 id “org.jetbrains.dokka” version “0.9.17” 语句

2)错误二

What went wrong:
A problem occurred evaluating project ‘:spring-beans’.
No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency
Possible solutions: values
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Spring5源码导入idea
解决方法:修改 D:\spring-framework-5.0.2.RELEASE\spring-beans\spring-beans.gradle 文件
注掉 compileGroovy.dependsOn = compileGroovy.taskDependencies.values - ‘compileJava’ 语句

3、编译成功

Spring5源码导入idea

四、导入idea

1、导入

1)选择new project
不要直接open文件夹,否则会导致系统无法正常构建
Spring5源码导入idea
2)选择使用gradle构建代码
Spring5源码导入idea
3)选择Spring源码根目录,Finish即可
4)导入完成
Spring5源码导入idea

上一篇:Gradle编译 Spring5源码


下一篇:Spring5-IOC容器笔记