踩过很多坑,参考过很多博客,在不懈的坚持下终于迈进了spring源码的门槛
本博客使用的是 ideal2020.3
+gradle-6.4.1
+spring-framework-5.1.x
+jdk8
下载链接
我使用的是gradle-6.4.1-bin.zip
这个版本,下载好解压即可。
1.右键“这台电脑”–>“属性”–>“高级系统设置”–>“环境变量”–>“系统变量”
2.新增一个GRADLE_HOME值gradle为解压后的路径
3.系统变量中修改Path变量,将Gradle的bin目录添加进去, 将gradle解压路径添加到Path变量 : ;D:\DJWORK\25gradle\gradle-6.4.1\bin
4.查看安装的gradle的版本信息。
使用快捷键Win+R弹出的输入框中输入cmd,然后打开命令窗口,在命令窗口中输入gradle -v 或 gradle -version 可以查看到gradle的版本信息
在将Spring源码导入Idea时, 为了加快gradle下载依赖包的效率, 在以下配置文件中添加配置
maven { url "https://maven.aliyun.com/repository/spring-plugin" }
maven{ url "https://maven.aliyun.com/nexus/content/repositories/spring-plugin"}
maven { url "https://maven.aliyun.com/repository/central" }
1、buil spring-core和 spring-oxm
我们在运行自己添加的代码前先build一下spring的内核包。
在import-into-idea.md
导入手册中有下面这一句话:
spring-core
and spring-oxm
should be pre-compiled due to repackaged dependencies.所以按照顺序依次build
在进行spring-core
build时,控制台报错了
错误提示:
Spring源码编译时提示kotlin版本错误
Kotlin: Language version 1.1 is no longer supported; please, use version 1.3
解决办法:
打开build.gradle,找到compileKotlin和compileTestKotlin,并修改kotlin版本为较新的版本:
参考链接
进行spring-oxm也报错了
错误提示:
org.gradle.api.CircularReferenceException: Circular dependency between the following tasks:
:spring-beans:compileGroovy
— :spring-beans:compileJava
— :spring-beans:compileKotlin
— :spring-beans:compileGroovy (*)**
解决方法:
更改 Spring-Frameworkspring-beansspring-beans.gradle 文件,方法如下:
在文件最后注释掉下面三行代码
// def deps = compileGroovy.taskDependencies.immutableValues + compileGroovy.taskDependencies.mutableValues
// compileGroovy.dependsOn = deps - "compileJava"
// compileKotlin.dependsOn(compileGroovy)
添加如下代码
tasks.named('compileGroovy') {// Groovy only needs the declared dependencies (and not the result of Java compilation)classpath = sourceSets.main.compileClasspath
}
tasks.named('compileKotlin') {// Kotlin also depends on the result of Groovy compilationclasspath += files(sourceSets.main.groovy.classesDirectory)
}
单元测试时竟然没有反应
Intellij IDEA单元测试提示Test events were not received
控制台输出
解决办法
Idea导入Spring-farmework源码终极版
Idea导入SpringBoot源码终极版(基于Gradle)
idea导入spring源码终极教学
《Spring》第一篇 IDEA导入Spring源码