第一步、准备gradle环境

1、去官网下载gradle

​https://gradle.org/releases/​​​

1. 用IDEA搭建spring源码阅读环境_github

2、将其解压缩,创建​​repository​​​文件夹 和​​init.d​​文件夹

1. 用IDEA搭建spring源码阅读环境_idea_02

在​​init.d​​文件夹中创建​​init.gradle​​配置文件(​​类似于maven中的settings.xml​​)

输入文本信息,主要是配置阿里云镜像仓库地址,和maven的类似

gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
}

3、为了方便,设置环境变量​​GRADLE_HOME​​​ 和​​GRADLE_USER_HOME(看后面的截图就明白会被idea使用)​

GRADLE_HOME

gradle路径,例如:

D:\Program Files\gradle-6.8.3

1. 用IDEA搭建spring源码阅读环境_maven_03

第二步、下载spring源码

github下载源码比较慢,我们通过码云的方式将其下载下来。当然也可以直接从github的官网直接拉取下拉。

以下是同步到码云的操作

1. 用IDEA搭建spring源码阅读环境_github_04

1. 用IDEA搭建spring源码阅读环境_maven_05

确认后就可以同步完成了

由于从码云上拉取代码需要ssh校验

如果之前有弄过​​ssh-keygen -t rsa​​也就是在个人文件夹下有一个​​.ssh​​文件夹里面有一个公钥

如下,讲id_rsa.pub已文本打开,复制里面的内容。

1. 用IDEA搭建spring源码阅读环境_maven_06

1. 用IDEA搭建spring源码阅读环境_maven_07

然后我们就可以通过IDEA的get from version control

复制ssh的连接,然后粘贴到idea中,与github上的git操作一致

1. 用IDEA搭建spring源码阅读环境_spring_08

1. 用IDEA搭建spring源码阅读环境_idea_09

刷新一下gradle依赖,首次刷新会非常慢,如果遇到了错误提示,则根据错误提示进行处理。

完成后就会像我这样。gradle下的所有spring相关模块都被自动检测到

1. 用IDEA搭建spring源码阅读环境_spring_10

完成上面操作后spring的源码环境就算完成了。